Christian Giacomi

Go mod cheat sheet

Posted — Mar 15, 2019

This is a simple cheat sheet for go modules, listing the main commands.


Create a new module, with automatic module path resolution.

$ go mod init

go: creating new go.mod

Create a new module, with explicit module path.

$ go mod init

go: creating new go.mod: module

Clean up

Prune any no-longer-needed dependencies and add any dependencies needed for other combinations of OS and architectures.

$ go mod tidy


Create a vendor directory with the exact version of the dependencies to use during build.

$ go mod vendor


Why a module or package is being kept.

go mod why module


Display the dependencies of your module.

go mod graph
If this post was helpful tweet it or share it.