How to Create and Publish a Go Module

Initialize a go.mod file, tag a version in git, and push to a public repository to publish a Go module.

Create a go.mod file, tag a version in your version control system, and push the code to a public repository to publish a Go module.

  1. Initialize the module with a unique import path. go mod init github.com/yourusername/yourmodule
  2. Tag the current commit with a semantic version number. git tag -a v1.0.0 -m "Release v1.0.0"
  3. Push the code and the tag to the remote repository. git push origin main --tags

The module is now available for others to import via go get.