docker buildx warns: failed to read current commit information with git
WARNING: buildx: failed to read current commit information with git rev-parse --is-inside-work-treeShort answer
buildx reads Git information to add source details to the image provenance. The warning means that git rev-parse failed in the build directory. The folder may be owned by another user, so Git refuses it. If you do not need the source details, set BUILDX_GIT_INFO=0 and buildx stops asking Git.
Fix it fast
1Find out which cause you have
Run the exact command buildx runs, in the folder you build from, and read what Git itself says.
git rev-parse --is-inside-work-tree2Match what you see, then jump to its fix
What does the error look like?
WARNING: buildx: failed to read current commit information with git rev-parse --is-inside-work-tree
Cause 1 of 2
Git refuses the folder because another user owns it
1Check
Git refuses to read the config of a repository owned by someone else unless the path is listed in safe.directory. This is common in CI jobs and containers that run as a different user than the checkout.
ls -ld .
id -un2Fix
Add that one directory to the global safe.directory list. It is read only from global or system config, not from the repository itself. Avoid the * wildcard, which turns the check off for everything.
git config --global --add safe.directory "$(pwd)"3Verify
The command now prints true.
git rev-parse --is-inside-work-treeConfirmed by git-scm.com
Cause 2 of 2
The build folder is not a Git work tree
1Check
The git-rev-parse manual says --is-inside-work-tree prints true only inside the work tree of a repository. A copied folder without .git, or a build started in a bare repository, does not count.
git rev-parse --show-toplevel2Fix
Run the build from the repository's work tree. If the build intentionally has no repository, turn off the Git lookup, which the Docker docs say removes source control information from provenance.
export BUILDX_GIT_INFO=03Verify
Run the build again. The warning no longer appears.
docker buildx build .Confirmed by docs.docker.com
How do I stop it coming back?
- In CI, check out the code as the same user that runs docker build.
- Set BUILDX_GIT_INFO=0 in jobs that build from an exported tarball.
- Add a single safe.directory entry per trusted path, never the wildcard.
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.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
docker build says BuildKit is enabled but the buildx component is missing or broken
ERROR: BuildKit is enabled but the buildx component is missing or broken.
docker build is backed by the buildx plugin.
2 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fix