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

