Go "error obtaining VCS status" (buildvcs) in CI
Since Go 1.18, go build stamps version control info into the binary. When it cannot read the git repository (dubious ownership, a shallow or missing checkout), it fails and suggests -buildvcs=false.
What this error means
go build fails with "error obtaining VCS status: exit status 128 ... use -buildvcs=false to disable VCS stamping", often alongside git "detected dubious ownership".
error obtaining VCS status: exit status 128
Use -buildvcs=false to disable VCS stamping.Common causes
Git refuses the repository ownership
The runner user differs from the checkout owner, so git reports "dubious ownership" and the VCS query that go build runs fails.
No usable .git directory in the build context
Building inside a container or from an archive without the .git directory leaves go build unable to read VCS status.
How to fix it
Mark the checkout safe for git
- Add the workspace path to git safe.directory.
- Re-run the build so VCS stamping can read the repo.
- This keeps the embedded version metadata intact.
git config --global --add safe.directory "$GITHUB_WORKSPACE"
go build ./...Disable VCS stamping when there is no repo
If the build context has no git repository (a container build from a tarball), turn off stamping.
go build -buildvcs=false ./...How to prevent it
- Set
safe.directoryfor the workspace in container builds. - Keep the
.gitdirectory available where you need version stamping. - Use
-buildvcs=falsedeliberately when the binary should not embed VCS info.