Introduction: Why you might need a "live" commit
\nHave you ever written Go code, added a library via go get, and then discovered that its author fixed a critical bug but hasn't released a new tag (release) yet? Or maybe you're developing a library yourself and want to test it in your main project before publishing a version?
Go modules have a cool feature: you can specify in go.mod not just a version number (v1.2.3), but a specific commit from a Git repository. This allows you to work with the very latest code, even if it hasn't been wrapped in a release tag yet.
This article is a translation and adaptation of one of the most popular questions on Stack Overflow in the Go world. We'll break down how to do this correctly, what pitfalls exist, and how not to break your build.
\n\nWhat is go.mod and why are commits there?
\ngo.mod is a file located in the root of your Go project. It describes all the dependencies (modules) your application needs. Typically, lines look like this:
require (\n github.com/someuser/somelib v1.2.3\n)\nBut what if the feature you need isn't in v1.2.3, but only exists in the latest commit on the main branch? In Go, this is solved with pseudo-versions.
What is a pseudo-version?
\nThis is a special string that replaces a regular version number. It consists of:
\n- \n
- A base version (if there is a tag from which it branched) \n
- The commit timestamp (in
yyyymmddhhmmssformat) \n - The commit hash (first 12 characters) \n
Example: v0.0.0-20250320120000-abc123def456
Don't be afraid of this long string — it's almost always generated by the go tool itself.
Method #1: Using go get with the @latest flag
\nThis is the simplest and safest method. You simply tell Go: "Get the latest version from the repository."
\nStep 1: Open a terminal in the root of your project.
\nStep 2: Run the command:
\ngo get github.com/someuser/somelib@latest\nAfter this, Go will do the following:
\n- \n
- Download the latest commit from the default branch (usually
mainormaster). \n - Generate a pseudo-version. \n
- Automatically update
go.modandgo.sum. \n
Result in go.mod:
require (\n github.com/someuser/somelib v0.0.0-20250320120000-abc123def456\n)\nDone! You've just pinned your project to the very latest commit.
\n\nIf you need to specify a specific commit hash
\nIf you know the exact hash (e.g., abc123def456789), you can substitute it directly:
go get github.com/someuser/somelib@abc123def456789\nGo will convert it into a pseudo-version itself.
\n\nMethod #2: Manual editing of go.mod
\nSometimes you need to edit the file manually (for example, if you don't have terminal access or you're writing a CI script).
\nStep 1: Open go.mod in any editor.
Step 2: Find the line with the required dependency and replace the version with latest or a specific hash.
require (\n github.com/someuser/somelib latest\n)\nStep 3: Save the file and run in the terminal:
\ngo mod tidy\nThe go mod tidy command will fetch missing dependencies, remove unnecessary ones, and replace the word latest with the actual pseudo-version.
Important: If you simply write a hash manually (e.g., v0.0.0-abc123def456), Go may throw an error. It's always better to run go mod tidy after manual edits.