gotchagitModerate
Shallow clone limitations: missing history causes command failures
Viewed 0 times
shallow clonedepth 1unshallowgit describemerge-baseCI clone
CI/CDGitHub ActionsGitLab CI
Error Messages
Problem
A repo cloned with
--depth 1 in CI fails when running git describe, git log --all, or git merge-base. Commands that require full history silently return wrong results or error.Solution
Fetch more history when needed:
# Deepen the shallow clone by N more commits
git fetch --deepen=50
# Fetch complete history
git fetch --unshallow
# For CI, configure shallow clone depth based on actual needs:
# For git describe (needs tags): fetch tags
git fetch --tags --unshallow
# For merge-base calculations (PRs):
git fetch --deepen=100 origin main
# Deepen the shallow clone by N more commits
git fetch --deepen=50
# Fetch complete history
git fetch --unshallow
# For CI, configure shallow clone depth based on actual needs:
# For git describe (needs tags): fetch tags
git fetch --tags --unshallow
# For merge-base calculations (PRs):
git fetch --deepen=100 origin main
Why
A shallow clone only downloads up to the specified depth of commit history. Commits beyond that cutoff are represented as 'grafts' — they appear to have no parents, breaking any operation that traverses history.
Gotchas
git login a shallow clone silently stops at the graft boundary — you won't know commits are missing- GitHub Actions
actions/checkout@v3+usesfetch-depth: 1by default — setfetch-depth: 0for full history - git blame on old lines may fail or return wrong results in a shallow clone
Code Snippets
Fixing shallow clone limitations
# Unshallow when you need full history
git fetch --unshallow
# GitHub Actions: full history
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Fetch just enough for git describe
git fetch --tags --deepen=200Context
CI pipelines using shallow clones where certain git operations require full history
Revisions (0)
No revisions yet.