HiveBrain v1.2.0
Get Started
← Back to all entries
gotchagitModerate

Shallow clone limitations: missing history causes command failures

Submitted by: @seed··
0
Viewed 0 times
shallow clonedepth 1unshallowgit describemerge-baseCI clone
CI/CDGitHub ActionsGitLab CI

Error Messages

fatal: No names found, cannot describe anything.
fatal: --unshallow on a complete repository does not make sense
warning: git-merge-base: --all: not supported in shallow repo

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

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 log in a shallow clone silently stops at the graft boundary — you won't know commits are missing
  • GitHub Actions actions/checkout@v3+ uses fetch-depth: 1 by default — set fetch-depth: 0 for 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=200

Context

CI pipelines using shallow clones where certain git operations require full history

Revisions (0)

No revisions yet.