In Depth: Releasing v2 and Beyond of a Go Module

Go handles breaking changes differently from npm, PyPI or Cargo. A new major version is, in effect, a new module with a new import path. Once that clicks, the rest of the rules follow. This guide walks through the reasoning, both release methods, and what your users have to do.

The rule and the reason

The Go Modules Reference states that, from major version 2 onwards, the module path must end in a major version suffix such as /v2. Versions v0 and v1 have no suffix. The reasoning is the import compatibility rule: if an old package and a new package have the same import path, the new one must be backwards compatible with the old one. A breaking change therefore needs a different path. A useful side effect is that one program can depend on example.com/widget and example.com/widget/v2 at the same time, which makes gradual migration across a large codebase possible.

Method 1: the major branch

Keep the code at the repository root and change the module path in place.

// go.mod on the main branch after the change
module example.com/widget/v2

go 1.22
  1. Create a branch such as v1 from the last v1 tag so fixes can still be released there.
  2. On main, edit go.mod to add /v2.
  3. Update every import inside the module that refers to its own packages, for example example.com/widget/internal/codec becomes example.com/widget/v2/internal/codec.
  4. Make the breaking changes, run the tests, and tag v2.0.0.

Method 2: the major subdirectory

Copy the module into a v2/ directory with its own go.mod declaring the suffixed path. The Go command understands this layout, and it also works for older tooling that predates modules. The cost is duplicated code living side by side on one branch, so most projects today prefer the branch method unless they have a specific reason.

Common mistakes

MistakeWhat happensFix
Tagging v2.0.0 without changing the module pathThe Go command refuses the version, or treats it as +incompatible for a module without a go.modAdd the suffix and tag a new version
Forgetting internal self-importsThe v2 module silently imports v1 packagesSearch the tree for the old path before tagging
Retagging an existing versionChecksum mismatch errors for users, because the checksum database recorded the originalNever move a tag; publish a new patch and retract the bad one
Staying on v0 forever to avoid the ruleUsers get no stability signalRelease v1 when the API is settled

What consumers do

Upgrading is an explicit choice. A user runs go get example.com/widget/v2@latest and updates their import statements, file by file if they like, since both majors can coexist during the transition. Help them by publishing a short migration note listing renamed and removed identifiers, and consider keeping thin wrappers in v1 that point to v2 behaviour where that is practical.

Before you reach for v2

Because the cost to users is real, it is worth asking whether the change can be made additively: a new function beside the old one, a new option, or a new package within the same module. Go's culture leans toward long-lived v1 APIs, and many widely used modules have never needed a v2. Read more in the Go module publishing outline and the major version migration guide.