liveBook · Manning

Go mod tidy

As explained in Go in Action, Second Edition

go mod tidy is a Go command that synchronizes module dependencies and their checksums with the packages imported by a project.

go mod tidy synchronizes a Go module’s declared dependencies and checksums with the packages imported by the project. section 11.1

Running the command keeps module metadata aligned by:

  • Removing dependencies no longer imported. section 11.1
  • Adding missing dependencies imported by the code. section 11.1
  • Updating go.sum with dependency and go.mod checksums. section 11.1

After adding an import

Add a dependency’s package path to Go code, then run go mod tidy. The command fetches the dependency, records it in go.mod, and updates go.sum so builds use verified module contents. section 11.1

go mod tidy

Run the command from the module directory to reconcile imports, go.mod, and go.sum. section 11.1

How Go in Action, Second Edition covers it

How deep it goes
Explains cleanup, addition, and checksum updates, but does not detail the command’s internal resolution algorithm.
Examples
Uses an imported package, automatic dependency recording, and the go mod tidy command.
What it assumes
Assumes a Go module with go.mod and imported packages; explains metadata synchronization rather than module initialization.
What you can do after
Apply it via Go tooling to reconcile a project’s dependencies and checksum records.
How it connects
Connects module dependencies with go.mod, go.sum, imports, and cryptographic checksums.

Also explained in

Compare how 2 books explain go mod tidy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Action, Second Edition. The section links point to the parts of the book it draws on.