Having to run go mod vendor
every time I git checkout <branch>
is annoying.
If I forget, gopls
is unusable, tests cannot be run, and VSCode complains (go: inconsistent vendoring
).
Add a post-checkout hook that will run go mod vendor
in the background every time a branch is checked out.
Several ways possible. I chose one that allows me to keep all my Git config in one place. (Alternative: put the git config directly in your repo)
- Add this to your global
.gitconfig
:
[includeIf "gitdir:~/path/to/your/go/repo/"]
path = .gitconfig-go
- Add a
.gitconfig-go
file just next to it:
[core]
hooksPath = ~/path/to/git-go-hooks-folder
- Create the
git-go-hooks-folder
folder and insert thepost-checkout
file attached
git checkout
a branch, then tail vendor.log
It does not work on all git operations that might require a go mod vendor
(e.g. you might have to run go mod vendor
yourself after a rebase).