Git "reference is not a tree" on a shallow clone in CI
A shallow clone only fetches recent history. When a later step asks Git to check out or diff against a commit outside that window, the object is simply absent and Git reports the SHA as "not a tree".
What this error means
A checkout, git merge-base, or git diff against a base SHA or tag fails with fatal: reference is not a tree: <sha>. It works locally with a full clone but breaks in CI where the checkout used fetch-depth: 1.
git
fatal: reference is not a tree: 9fceb02d0ae598e95dc970b74767f19372d61af8Common causes
Shallow clone missing the target commit
actions/checkout defaults to fetch-depth 1. Any operation needing an older commit (PR base, previous tag) has no object to resolve.
The ref was never fetched
Single-branch or filtered clones omit branches and tags the step later references.
How to fix it
Fetch the history you need
- Set fetch-depth: 0 in actions/checkout to get full history, or a depth large enough to include the base.
- Alternatively fetch the specific commit or branch on demand.
.github/workflows/ci.yml
- uses: actions/checkout@v4
with:
fetch-depth: 0Deepen an existing shallow clone
- Unshallow in place when full history is needed late in the job.
- Or fetch just the missing ref to keep the clone small.
Terminal
git fetch --unshallow
# or fetch one ref:
git fetch --depth=1 origin <base-sha>How to prevent it
- Use fetch-depth: 0 for jobs that diff against a base branch, compute changed files, or read tags; reserve shallow clones for jobs that only build the tip.
Related guides
Git "Could not find remote branch" in CIFix the Git "fatal: Remote branch <name> not found in upstream origin" error in CI when a clone or checkout t…
Git "shallow update not allowed" in CIFix the Git "shallow update not allowed" push error in CI, which happens when you try to push from a shallow…
Git "RPC failed; curl 56 / HTTP 500" on a large clone in CIFix the Git "RPC failed; curl 56" and "HTTP 500" errors when cloning a large repository in CI, caused by conn…