Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

go build fails with error obtaining VCS status, exit status 128

Your error

error obtaining VCS status: exit status 1281 more line it can show

Fix it fast

Most common cause, 1 of 2

go build runs as root or a CI account that does not own the checkout

Build as the user who owns the checkout.

Fix
# build without sudo
go build -o app .

# or, inside the container or CI job that builds as another user
git config --global --add safe.directory /src
go build -o app .
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

error obtaining VCS status: exit status 128 means git status, which go build runs to stamp the binary, failed. Usually another user owns the repository (sudo, a container, CI), or .git points to a missing gitdir. go build -v shows git's real message; fix that, or pass -buildvcs=false. Applies to Go 1.26-1.27.

  • Applies to Go 1.27, Go 1.26, Git 2.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Go hides git's own message unless you ask for verbose output. Build again with -v in the same shell, user and container, and read the line that starts with fatal.

Run this first
go build -v ./... 2>&1 | grep -iE "^# cd|fatal"

Then find the line you see in this list and open its fix:

  1. 1go build runs as root or a CI account that does not own the checkoutThe fatal line says the repository is owned by someone else, and the build runs under sudo, as root in a container, or as a CI user
  2. 2A .git file points to a gitdir that is missing from this copyOwnership is fine, .git is a small file that starts with gitdir:, and the path after it does not exist where the build runs

What does the error look like?

  • error obtaining VCS status: exit status 128
  • Use -buildvcs=false to disable VCS stamping.

Cause 1 of 2

go build runs as root or a CI account that does not own the checkout

You seeThe fatal line says the repository is owned by someone else, and the build runs under sudo, as root in a container, or as a CI user

Check

go build reports exit status 128 here because Git refuses to read a repository owned by someone else, and Go treats that refusal as a failed VCS lookup. The Go issue tracker has the classic case: a plain build succeeds while sudo go build in the same folder fails. A container that bind-mounts your checkout and builds as root hits the same check.

Check
ls -ld .git
id -un

Fix

Build as the user who owns the checkout. When that is not possible, trust the exact path in the global or system Git config of the user that builds; Git ignores the setting inside the repository's own config.

Fix
# build without sudo
go build -o app .

# or, inside the container or CI job that builds as another user
git config --global --add safe.directory /src
go build -o app .

Verify

git status works for the building user, and the binary carries vcs.revision in its build info.

Verify
go version -m ./app | grep vcs

Confirmed by github.com

Did this fix it?

Cause 2 of 2

A .git file points to a gitdir that is missing from this copy

You seeOwnership is fine, .git is a small file that starts with gitdir:, and the path after it does not exist where the build runs

Check

Submodules and git worktree checkouts usually hold a gitfile: a plain .git text file naming the real repository directory elsewhere. Copy such a folder into a Docker build context or another machine without its parent repository and git cannot open it, so go build fails the stamp. An invalid .git in a parent directory has the same effect, as reported in the Go tracker for toolchain builds.

Check
cat .git
git rev-parse --git-dir

Fix

Build from a full clone, or leave .git out of the copied tree. With no repository found, Go's default auto mode skips stamping instead of failing. Use -buildvcs=false when you want a build that never depends on Git state.

Fix
# .dockerignore
.git

# or keep the files and opt out of stamping
go build -buildvcs=false -o app .
export GOFLAGS=-buildvcs=false   # for every go command in this job

Verify

The build completes; go version -m shows no vcs lines when stamping was skipped or disabled.

Verify
go version -m ./app

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Run go build in CI and containers as the same user that checked out the code, or add one safe.directory line for the checkout path in the image.
  • Decide whether release binaries need vcs.revision. If they do, build from a full clone; if not, set -buildvcs=false in the Makefile so the choice is explicit.
  • Keep .git out of Docker build contexts that copy only part of a repository, such as a single submodule.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.