go mod tidy

The go subcommand that adds any module your code imports but go.mod lacks, and removes any it lists but no longer uses.

In more detail

It rewrites go.mod (and its checksum file go.sum) to match the code as it is now. Run it before committing so the dependency list is honest. A pipeline can run it and fail if the files change, which catches a forgotten tidy.

Example

go mod tidy

Related terms

Taught in

References