🔀 Git: Fix a Shallow Clone Failing to Fetch an Old Tag
A shallow clone made with –depth N only downloads the N most recent commits reachable from the cloned ref, and by default it doesn’t fetch any tag whose commit falls outside that shallow history window, so a later git fetch –tags, or a direct checkout of an old tag name, fails with the tag’s commit reported as missing, even though the tag genuinely exists on the remote, because the shallow clone’s object database was never given that commit in the first place.
🔎 The Problem
git clone --depth 1 https://github.com/example/repo.git cd repo git checkout v1.2.0 # fatal: reference is not a tree: v1.2.0 # v1.2.0 exists on the remote, but its commit is older than # the single commit --depth 1 actually downloaded, and a # shallow clone's fetch config excludes old tags by default
✅ Fix: Deepen Just Enough, or Unshallow Entirely
- Run
git fetch --depth=1000000000 origin tag v1.2.0, or a specific--shallow-since/--deepenvalue, to pull in just enough history to reach that one tag’s commit, rather than re-cloning the whole repository at full depth. - Convert the existing shallow clone into a full one with
git fetch --unshallowwhen more than one old tag or commit range is needed, since repeatedly deepening a shallow clone tag-by-tag gets slower than unshallowing it once. - For CI pipelines that only ever need the latest commit, keep the shallow clone but document that any job needing an older tag must unshallow first, rather than letting a cryptic “reference is not a tree” error be the first anyone learns of the limitation.
🚨 Why This Is Dangerous
- A shallow clone’s missing-tag error reads exactly like a typo in the tag name or a genuinely deleted release, and tracking down that it’s actually a depth limitation can waste real time on the wrong hypothesis before anyone checks how the repository was cloned.
A shallow clone doesn’t just skip history — it skips every tag that history anchors, whether or not anyone pruning for speed meant to lose it.





