Automatic go mod vendor after git operations. Never run it manually again.
If your Go project uses vendoring, every git pull, branch switch, or rebase that changes go.mod leaves vendor/ out of sync. Your IDE breaks with errors like:
Error loading workspace: packages.Load error: go: inconsistent vendoring
You have to remember to run go mod vendor every time. The Go team has known about this since 2021, but no upstream fix exists.
autovendor installs lightweight git hooks that detect dependency changes and automatically sync your vendor directory. It supports monorepos with multiple Go modules.
Homebrew:
brew install mpartipilo/autovendor/autovendorOr tap once, then use the short name forever:
brew tap mpartipilo/autovendor
brew install autovendorGo install:
go install github.com/mpartipilo/autovendor@latestmise:
mise use -g github:mpartipilo/autovendorQuick try (no install):
go run github.com/mpartipilo/autovendor@latest installcd ~/src/your-go-project
autovendor installThat's it. From now on, go mod vendor runs automatically after:
git pull/git merge(post-merge hook)git checkout/ branch switches (post-checkout hook)git rebase(post-rewrite hook)
It only runs when go.mod or go.sum actually changed, so there's no overhead on unrelated pulls.
autovendor install ~/src/another-projectautovendor uninstall-
autovendor installdetects your repo's hooks directory (respectscore.hooksPathconfig) and installs thin shell scripts forpost-merge,post-checkout, andpost-rewrite. -
Each hook first tries the
autovendorbinary on your PATH. If not found, it falls back togo run github.com/mpartipilo/autovendor@v{version}— pinned to the exact version that was installed. This means hooks work even on machines withoutautovendorinstalled (only Go is required). -
The hook calls
autovendor run <hook-type>, which:- Determines the old and new git refs for the operation
- Runs
git diff --name-onlyto find changedgo.mod/go.sumfiles - For each affected module directory that has a
vendor/folder, runsgo mod vendor
-
Monorepo support: If your repo has multiple Go modules (e.g.,
services/auth/go.mod,tools/lint/go.mod), only the modules whose dependencies changed are re-vendored. -
Plays nice with existing hooks: If you already have git hooks, autovendor appends its block (wrapped in
# autovendor:begin/endmarkers) without clobbering your existing scripts. Uninstall cleanly removes only the autovendor block.
autovendor: go.mod changed in ., running go mod vendor...
autovendor: vendor synced in . ✓
- Go (for
go mod vendor) - Git
The go run fallback in each hook is pinned to the exact version of autovendor that was used during autovendor install. For example, if you install with v1.0.0, the hooks will contain:
go run github.com/mpartipilo/autovendor@v1.0.0 run post-merge "$@"This prevents supply chain attacks — a compromised future version cannot be silently pulled in by your hooks. To upgrade, run autovendor uninstall && autovendor install with the new version.
Does it slow down git pull?
No — it only runs go mod vendor when go.mod or go.sum actually changed. On pulls with no dependency changes, it's a no-op.
What if I don't use vendoring?
autovendor checks for a vendor/ directory before running anything. If your module doesn't vendor, it's a no-op even if go.mod changed.
Does it work with git worktrees?
Yes — it uses git rev-parse --git-dir to find the correct hooks location.
Can I use it alongside other git hook tools (lefthook, husky, pre-commit)? Yes — autovendor wraps its block in markers and appends to existing hooks rather than replacing them.
How do I upgrade autovendor in an existing repo? Install the new version of autovendor, then re-install the hooks to update the pinned version:
autovendor uninstall
autovendor installautovendor ships a usage-cli spec file (autovendor.usage.kdl). If you have usage installed, you can generate shell completions:
usage g completion bash autovendor -f autovendor.usage.kdl > ~/.bash_completions/autovendor.bash
usage g completion zsh autovendor -f autovendor.usage.kdl > ~/.zsh_completions/_autovendor
usage g completion fish autovendor -f autovendor.usage.kdl > ~/.config/fish/completions/autovendor.fishMIT