To publish a Go module with semantic versioning, give it a module path that matches where it is hosted, commit your code, and push a Git tag such as v1.2.3. The go command and the module proxy read that tag as the version, so there is no upload step and no registry account. This guide covers the tagging rules, the v2 major version path rule, and the checks to run before you release, which is the practical core of how to publish a Go module with semver.
Versions are derived from version control, so a bad tag is the main way to get stuck. Learn how the rules work before you push your first one.
A Go version has the form vMAJOR.MINOR.PATCH, with a mandatory leading v. The meaning follows semantic versioning.
| Part | Increase it when |
|---|---|
| MAJOR | You make a backward incompatible change to the exported API |
| MINOR | You add backward compatible functionality |
| PATCH | You make backward compatible bug fixes |
Versions below v1.0.0 (such as v0.4.2) tell users the API is not stable yet, and Go does not require a path suffix for them. A pre-release such as v1.3.0-rc.1 sorts before v1.3.0 and is only chosen when a user asks for it explicitly. Go's minimal version selection then picks the highest version required anywhere in the build, never a newer one automatically.
Start with a go.mod whose module path is the repository URL where users will fetch it.
Before tagging, run the usual checks from the module root.
go mod tidy removes unused requirements and adds missing ones, so the published go.mod and go.sum describe your real dependencies. Commit the result. Add a license file and a short README, because pkg.go.dev shows both and refuses to display documentation for modules without a recognised license.
A release is a Git tag on a commit that contains the go.mod file.
Ask the proxy to fetch it, which also warms the cache and makes the version show up on pkg.go.dev:
Users then add it with go get github.com/acme/[email protected], or @latest for the newest non pre-release tag. For a module that lives in a subdirectory of a repository, the tag needs the directory as prefix, for example tools/slug/v1.0.0.
Treat published tags as immutable. The proxy and go.sum checksums record the first content they saw, so moving a tag later causes checksum mismatch errors for users. If you tag something wrong, publish a new patch version and, if the bad version is harmful, add a retract directive.
The import compatibility rule says that packages with the same import path must stay backward compatible. A breaking change therefore needs a new import path. For v2 and higher, add the major version to the module path.
Users import github.com/acme/slug/v2, and the tag is v2.0.0. Both major versions can then be used in one build. You can keep v2 on the main branch (update go.mod, imports inside the module, and tag), which is the simplest layout for most projects. Never tag v2.0.0 while go.mod still says module github.com/acme/slug, because the go command rejects that version as invalid. Fix the module path and tag a new version such as v2.0.1; do not move the bad tag.
If you ship a broken release, you cannot delete it from the proxy, but you can mark it in a later version's go.mod.
Publish a new version containing the directive, for example v1.0.2. Tools such as go list -m -u then warn users who run the retracted version, and @latest skips it.
Without a tag, a user can depend on a commit and Go builds a pseudo version like v0.0.0-20261110120000-abcdef123456. Use that for testing, not for releases.
go mod tidy, go vet ./... and go test ./....gorelease (from golang.org/x/exp), which reports the minimum next version.v prefix.pkg.go.dev.No. The tag in your public repository is the release. The default proxy fetches and caches it the first time someone requests that version.
Yes. Set GOPRIVATE (for example GOPRIVATE=github.com/acme/*) so the go command fetches directly from your repository and skips the public proxy and checksum database.
You tagged v2 or higher but the module path in go.mod has no /v2 suffix. Fix the path, commit, and tag a new version.
Not from the proxy. Use retract and publish a fixed version.
A Go module release is a semver Git tag with a v prefix on a commit that holds a valid go.mod. Run go mod tidy, vet and tests first, push the tag, and request it through the proxy. Add /v2 and higher to the module path for breaking changes, never move a published tag, and use retract to warn users about a bad release.