Go: No Vendor in Master

Sep 11, 2017

The vendor is nice especially for us who are unstable on the Internet. We can pack all dependents by tools like govendor.

However, at the same time, it pollutes the master branch. So your commit tree looks like this:

$ git log
commit 2a7465c5ab3e277b...
Author: Kaleo Cheng ...
Date:   Mon Sep 11 ...

    Add package for hello

commit 2a7465cdddsgjt7t5...
Author: Kaleo Cheng ...
Date:   Mon Sep 11 ...

    Add hello

It looks ugly and makes the master branch more and more bloated. To solve this, we can use the git worktree:

# First make a empty branch
$ git checkout --orphan vendor
$ git reset --hard
$ git commit --allow-empty -m "Initializing vendor "
$ git push origin vendor
$ git checkout master

# Then add worktree to vendor
$ git worktree add -B vendor vendor origin/vendor

Then you can commit in two branches separately:

$ git add . && git commit -m "Add hello"
$ cd vendor
$ git add . && git commit -m "Add package for hello"

Also, your commit tree looks like this for now:

$ git log
commit 2a7465cdddsgjt7t5...
Author: Kaleo Cheng ...
Date:   Mon Sep 11 ...

    Add hello
    
$ cd vendor
$ git log
commit 2a7465c5ab3e277b...
Author: Kaleo Cheng ...
Date:   Mon Sep 11 ...

    Add package for hello