Christian Giacomi

My personal software development blog

Go mod cheat sheet

A simple cheat sheet when using Go modules

Posted — Mar 15, 2019   Category — software  reference 

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.