Docker buildx "failed to read current commit information" (--build-context git) in CI
When you pass a git URL or rely on a git-backed build context, buildx runs git rev-parse to pin the commit. If the directory is not a git work tree, the history is shallow, or .git was stripped, that probe fails and the build aborts before it starts.
What this error means
A docker buildx build with a git context fails immediately with error: failed to read current commit information with git rev-parse --is-inside-work-tree.
error: failed to read current commit information with git rev-parse --is-inside-work-treeCommon causes
The checkout is not a git work tree
A tarball checkout or a copied directory has no .git, so rev-parse cannot identify a commit.
A shallow clone with missing refs
A fetch-depth: 0-less checkout can leave buildx unable to resolve the commit it wants to pin.
The build ran outside the repo directory
Invoking the build from a parent or sibling directory that is not inside the work tree trips the same probe.
How to fix it
Ensure a real git checkout with full history
- Use
actions/checkoutwithfetch-depth: 0so the work tree and refs exist. - Run the build from inside the checked-out repo.
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: docker buildx build -t myorg/app:ci .Pass a non-git context when git is unavailable
- If the source is not a git tree, build from the local path directly.
- Drop the git URL form and point at the directory.
docker buildx build -t myorg/app:ci /home/runner/work/app/appHow to prevent it
- Check out with
fetch-depth: 0when builds depend on git context. - Run buildx from inside the repository work tree.