Skip to content
Latchkey

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".

go build
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

  1. Add the workspace path to git safe.directory.
  2. Re-run the build so VCS stamping can read the repo.
  3. This keeps the embedded version metadata intact.
Terminal
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.

Terminal
go build -buildvcs=false ./...

How to prevent it

  • Set safe.directory for the workspace in container builds.
  • Keep the .git directory available where you need version stamping.
  • Use -buildvcs=false deliberately when the binary should not embed VCS info.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →