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 --unshallowwhen 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 -sUnshallow example
Terminal
git fetch --unshallow --no-tags
git describe --tags --alwaysGotchas
--unshallowon a very large repo can cost as much as a full clone; prefer--deepenwith a bounded number.- Deepen fetches the same objects each run; a git cache avoids re-downloading them.
Related guides
How to Do a Shallow Clone in CI for a Large RepositorySpeed up checkout of a large repository in GitHub Actions with fetch-depth: 1 for a shallow clone, and learn…
How to Cache the Git Repository Between CI RunsCache the .git directory in GitHub Actions with actions/cache so a large repository fetches only new objects…