Skip to content
Latchkey

Git Shallow Clone Missing History - fetch-depth Too Small in CI

A shallow clone is fast but only contains the most recent commit(s). Any command that needs older history - a version derived from tags, a diff against main, a commit count - fails or returns wrong results.

What this error means

A build works locally with full history but in CI a step like git describe, git merge-base origin/main HEAD, or a "changed files since base" diff fails or yields empty/incorrect output. The repo was cloned with the default shallow depth.

CI log
$ git describe --tags
fatal: No names found, cannot describe anything.

$ git merge-base origin/main HEAD
fatal: Not a valid object name origin/main

Common causes

Default fetch-depth is 1

actions/checkout defaults to fetch-depth: 1, fetching only the checked-out commit. Tags, the base branch, and prior commits are absent, so history-dependent commands have nothing to work with.

Only one branch was fetched

A shallow single-branch clone has no origin/main ref locally, so diffs and merge-base calculations against the base branch fail outright.

How to fix it

Fetch full history and tags

For version derivation and base-branch diffs, fetch everything.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0      # all commits
    fetch-tags: true    # ensure tags are present

Fetch just the base branch you compare against

If full history is too heavy, fetch only the ref you diff against.

Terminal
git fetch --no-tags --depth=1 origin main
git diff --name-only origin/main...HEAD

How to prevent it

  • Use fetch-depth: 0 for release/versioning jobs that read tags.
  • Explicitly fetch the base branch before any diff-against-base step.
  • Keep shallow clones for plain build/test jobs that need no history.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →