go mod tidy, vendor, download & graph
Module maintenance commands keep go.mod honest, warm caches, vendor sources for offline builds, and visualize why one version won over another.
Search across all documentation pages
Module maintenance commands keep go.mod honest, warm caches, vendor sources for offline builds, and visualize why one version won over another.
go mod tidy aligns require directives with imports actually referenced in your module.
go mod download fetches modules into GOMODCACHE without compiling.
go mod vendor copies required module sources into vendor/ for -mod=vendor builds.
go mod graph prints the module requirement graph MVS consumed.
Use them after dependency changes, before release branches, and when debugging version selection.
Quick-reference recipe card - copy-paste ready.
# Normalize requires after a refactor
go mod tidy
# Warm module cache in CI without compiling
go mod download all
# Materialize sources for air-gapped or audited builds
go mod vendor
# Inspect requirement edges (module@version pairs)
go mod graph | headWhen to reach for this:
go mod tidy on every PR that adds or removes imports.go mod download as an early CI step with a cached GOMODCACHE.go mod vendor when policy requires reviewing third-party source in-repo.go mod graph into graph tools when explaining a surprising transitive version.# Start from a module that imports x/sync
go get golang.org/x/sync@v0.10.0
# Add an import in code, remove another, then tidy
go mod tidy
# Pre-fetch everything the build list needs
go mod download all
# Vendor for -mod=vendor CI job
go mod vendor
# Build using only vendor/ + stdlib
go build -mod=vendor -o bin/worker ./cmd/worker
# See why v0.10.0 appears
go mod graph | rg 'golang.org/x/sync'// cmd/worker/main.go
package main
import (
"fmt"
"golang.org/x/sync/errgroup"
)
func main() {
var g errgroup.Group
g.Go(func() error { fmt.Println("task"); return nil })
_ = g.Wait()
}What this demonstrates:
go get records a version; tidy prunes anything no longer imported.download populates GOMODCACHE for faster later compiles.vendor plus -mod=vendor builds without reaching module proxies.go mod graph helps audit edges after upgrades.tidy loads all packages in the module, walks imports, and rewrites go.mod require blocks to the minimal set at chosen versions.go.sum with hashes for direct and indirect modules retained.download resolves the build list and copies .zip archives into the module cache; no .a files are built.vendor repeats download then extracts sources under vendor/<module>/, rewriting go.mod with an optional go mod vendor comment marker.| Command | Modifies go.mod | Modifies vendor/ | Network |
|---|---|---|---|
go mod tidy | Yes | No | May fetch sums |
go mod download | No | No | Yes (unless cached) |
go mod vendor | Adds comment | Yes | Yes (unless cached) |
go mod graph | No | No | No |
go mod verify | No | No | No (local check) |
# Typical regulated pipeline
go mod tidy
go mod vendor
git add go.mod go.sum vendor/
go test -mod=vendor ./...# Explain a selected version
go mod why -m golang.org/x/sync
# JSON module list for SBOM tooling
go list -m -json allgo test ./... after every tidy.go.mod without re-vendoring breaks -mod=vendor CI. Fix: automate go mod vendor in the same commit as dependency bumps.vendor/ unless policy demands.download compiles - it only fetches zips; compile errors appear later at go build. Fix: follow download with go test in CI.go mod verify failures - indicates cache tampering or incomplete go.sum. Fix: investigate proxy mirrors; do not delete sums blindly.go mod why instead of hand-editing.| Alternative | Use When | Don't Use When |
|---|---|---|
go work workspaces | Local multi-module dev without publishing | Single-module services |
replace directives | Temporary forks or local paths | Long-term version pinning (use proper tags) |
| Athens / Artifactory proxy | Shared module cache inside the org | Public open source with direct proxy.golang.org |
renovate / dependabot | Automated bump PRs | You lack CI to run tidy/test on each bump |
download fetches module content into the cache only.
go get also changes go.mod requirements.
When builds must not contact module proxies (air gap) or compliance mandates reviewing third-party source in git.
It removes modules neither imported nor needed to satisfy MVS.
Some indirect lines remain when a transitive version matters.
Each line is parent@version child@version, a requirement edge before MVS pruning.
It is not identical to the final build list.
go mod vendor vendors the full build list.
Selective vendoring is unsupported; use replace to a fork if you must trim.
Run go mod tidy or go get to refresh go.sum.
If mismatch persists, verify proxy integrity and module tags.
Yes for modules without vendor/.
It fails builds that would mutate go.mod silently.
The directory storing extracted module trees and zip caches.
Share it in CI caches to speed jobs.
After any change to imports or go get/go install that updates dependencies.
Many teams run it in pre-commit hooks.
It includes modules needed to build packages in your module, including test imports.
Use go list -test to see test-only edges.
go mod tidy example-mod=vendor buildsStack versions: This page was written for Go 1.26.x (Green Tea GC default, go fix modernizers - verify patch at build), chi (latest - verify at build), gin (latest - verify at build), echo (latest - verify at build), google.golang.org/grpc (latest - verify at build), sigs.k8s.io/controller-runtime (latest - verify at build), kubebuilder (latest - verify at build), tinygo (latest - verify board targets at build), wazero (latest - verify at build), and golangci-lint (latest - verify linter set at build).
Reviewed by Chris St. John·Last updated Jul 18, 2026