Skip to content
Latchkey

How to Deepen a Shallow Clone Only When Needed in CI

git fetch --deepen=N adds N more commits to a shallow clone, and --unshallow converts it to full history without re-cloning.

You do not have to choose between a fast shallow clone and having history available. Check out shallow, then deepen only in the specific step that needs older commits.

Steps

  • Check out with fetch-depth: 1.
  • In the step that needs history, run git fetch --deepen=50 (or a depth that covers your range).
  • Use git fetch --unshallow when you cannot predict how deep you need.

Workflow

.github/workflows/ci.yml
steps:
  - uses: actions/checkout@v4
    with:
      fetch-depth: 1
  - name: Generate changelog
    run: |
      git fetch --deepen=100
      npx conventional-changelog -p angular -i CHANGELOG.md -s

Unshallow example

Terminal
git fetch --unshallow --no-tags
git describe --tags --always

Gotchas

  • --unshallow on a very large repo can cost as much as a full clone; prefer --deepen with a bounded number.
  • Deepen fetches the same objects each run; a git cache avoids re-downloading them.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →