go mod tidy is a Go command that adds missing module requirements and removes unnecessary ones from module metadata.
go mod tidy cleans Go module metadata after dependencies change. It re-walks the dependency graph so the packages required by the project remain compatible and satisfied. section 6.1.3section 1.2.4
Use the command as part of a dependency-maintenance workflow:
Initialize the project with go mod init, which creates go.mod and records the Go version and dependencies. section 1.2.4
Select a specific dependency version with go get [package]@0.1.1 when the latest release is not wanted. section 6.1.3
Update all dependencies with go get -u, then run go mod tidy to clean and reconcile the dependency tree. section 6.1.3
Update one dependency with go get -u [package], remembering that transitive dependencies may also change. section 6.1.3
Inspect resulting versions and their dependencies with go mod graph; use go get -t when test-only packages matter. section 6.1.3
Refresh module dependencies
$ go get -u
$ go mod tidy
$ go mod graph section 6.1.3
How Go in Practice, Second Edition covers it
How deep it goes
Explains the command’s dependency-graph walk and workflow role, but stops short of internal resolution algorithms.
Examples
Uses go get -u followed by go mod tidy, with go mod graph for inspecting resulting dependency versions.
What it assumes
Assumes a Go project initialized with go mod init and dependencies managed through go get.
What you can do after
Operate/configure module metadata and verify dependency changes after updating or removing requirements.
How it connects
Connects module cleanup with go mod init, go get, semantic versioning, transitive dependencies, and go mod graph.
Go in Action, Second Editiongo mod tidy is a Go command that synchronizes module dependencies and their checksums with the packages imported by a project.
go.sumproduces · go.sum is a Go module checksum file that records cryptographic checksums for downloaded module dependencies.
go.mod fileproduces · A go.mod file is a Go module manifest that declares the module path, Go language version, and required dependencies.
dependency graphconfigures · A dependency graph is a graph whose nodes represent entities and whose edges represent dependency relationships among them.
go moduleconfigures · A Go module is a versioned collection of related Go packages defined by a go.mod file and managed as a unit for dependency resolution and builds.
This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.