How to Version a Go Module with Semantic Versioning

Retract a Go module version by adding a retract directive to go.mod, bumping the version, and pushing a new tag.

Version a Go module by adding a retract directive to your go.mod file and publishing a new version with the updated file.

  1. Add a retract directive to your go.mod file specifying the versions to retract.
retract v1.0.0
  1. Increment your version number in go.mod to the next semantic version.
module example.com/myapp

go 1.21

retract v1.0.0
  1. Commit the changes and create a new git tag matching the new version.
git add go.mod
git commit -m "Retract v1.0.0 and release v1.0.1"
git tag v1.0.1
git push origin v1.0.1
  1. Verify the retraction is visible on the module proxy.
go list -m -versions example.com/myapp