cicd git_operation ai_generated true

fatal: --unshallow on a complete repository does not make sense

ID: cicd/gha-shallow-clone-missing-history

Also available as: JSON · Markdown
92%Fix Rate
90%Confidence
110Evidence
2019-11-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
any active

Root Cause

GitHub Actions' actions/checkout defaults to fetch-depth: 1 (shallow clone). Git operations requiring history (git log, git describe, semantic-release, changelog generation) fail because commits, tags, or merge bases are missing.

generic

Workarounds

  1. 95% success Set fetch-depth: 0 in actions/checkout to get full history
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0  # Fetches all history for all branches and tags
        # Required for: git describe, semantic-release, changelog generation

    Sources: https://github.com/actions/checkout#usage

  2. 90% success For PR diff only, fetch the base branch with enough depth
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - run: git fetch origin ${{ github.base_ref }}
    # Now git diff origin/${{ github.base_ref }}...HEAD works correctly

    Sources: https://github.com/actions/checkout#usage

  3. 92% success For semantic-release or git describe, also fetch tags
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
        fetch-tags: true  # Available in actions/checkout@v4+
    # Or manually:
    - run: git fetch --tags origin

    Sources: https://github.com/actions/checkout#usage

Dead Ends

Common approaches that don't work:

  1. Running git fetch --unshallow in a step after checkout 55% fail

    While this works in some cases, it re-fetches the entire history which is slow for large repos. It also fails if the repo was already fully cloned (error: --unshallow on a complete repository). Use fetch-depth: 0 in checkout instead.

  2. Setting fetch-depth to a large fixed number like 100 or 500 60% fail

    A fixed depth is a guess that may still be insufficient. If the needed commit (merge base, tag, or blame target) is beyond that depth, the operation still fails. Only fetch-depth: 0 guarantees all history is available.

Error Chain

Preceded by:
Frequently confused with: