Appearance
Git clone cheat sheet
Core strategies
| Strategy | Command | Use case |
|---|---|---|
| Shallow | git clone --depth 1 <url> | Build-only CI, no history needed |
| Shallow (N) | git clone --depth 10 <url> | PR pipelines needing merge-base |
| Shallow (date) | git clone --shallow-since="2 weeks ago" <url> | CI with recent history context |
| Single branch | git clone --single-branch <url> | Default branch only |
| Blobless partial | git clone --filter=blob:none <url> | Full history, on-demand blobs |
| Treeless partial | git clone --filter=tree:0 <url> | Commit metadata only |
| Reference | git clone --reference-if-able=/cache/repo.git <url> | Fastest on persistent runners |
| Bundle | git clone repo.bundle | Air-gapped / offline |
Combine for maximum speed
bash
# PR check: shallow + blobless + sparse
git clone --filter=blob:none --depth=10 --single-branch <url>
cd repo && git sparse-checkout set src/ tests/
# Build only: depth 1, single branch
git clone --depth=1 --single-branch <url>
# Release: full history, single branch (needs tags)
git clone --single-branch <url>CI one-liners
bash
# GitHub Actions (manual override for blobless partial)
git init repo && cd repo && git remote add origin $URL && \
git fetch --depth=10 --filter=blob:none origin $REF && \
git checkout FETCH_HEAD
# Forgejo / Gitea depth
git clone --depth=1 --single-branch $URL .
# Shallow with merge-base fix
git clone --depth=10 $URL && cd repo && \
git fetch --deepen=100 origin mainReference cache setup
bash
# One-time mirror
git clone --mirror $URL /cache/repo.git
# Daily refresh
git -C /cache/repo.git fetch --prune
# CI checkout (self-contained)
git clone --reference-if-able=/cache/repo.git \
--dissociate --single-branch $URL .Recovery commands
bash
# Unshallow a shallow clone
git fetch --unshallow
# Deepen by N commits
git fetch --deepen=100
# Materialize blobs in partial clone
git checkout HEAD -- .
# Check for missing promisor objects
git rev-list --missing=print --all
# Verify protocol v2 support
GIT_TRACE_PACKET=1 git clone --filter=blob:none $URL 2>&1 | grep "version 2"Key config
ini
# Enable protocol v2 globally
git config --global protocol.version 2
# Skip LFS in CI
GIT_LFS_SKIP_SMUDGE=1 git clone $URL