Skip to content
Latchkey

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.

docker
error: failed to read current commit information with git rev-parse --is-inside-work-tree

Common 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

  1. Use actions/checkout with fetch-depth: 0 so the work tree and refs exist.
  2. Run the build from inside the checked-out repo.
workflow
- 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

  1. If the source is not a git tree, build from the local path directly.
  2. Drop the git URL form and point at the directory.
Terminal
docker buildx build -t myorg/app:ci /home/runner/work/app/app

How to prevent it

  • Check out with fetch-depth: 0 when builds depend on git context.
  • Run buildx from inside the repository work tree.

Frequently asked questions

What causes ""failed to read current commit""?
A tarball checkout or a copied directory has no .git, so rev-parse cannot identify a commit.
How do I fix "failed to read current commit"?
Ensure a real git checkout with full history

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card