Git Shallow Clone for Large Repos
Shallow clone techniques to reduce download size by limiting commit history depth.
# Shallow clone with only the latest commit
git clone --depth 1 https://github.com/user/repo.git
# Shallow clone with last 10 commits
git clone --depth 10 https://github.com/user/repo.git
# Shallow clone since a specific date
git clone --shallow-since="2024-01-01" https://github.com/user/repo.git
# Shallow clone excluding certain branches
git clone --shallow-exclude=legacy https://github.com/user/repo.git
# Convert shallow clone to full clone later
git fetch --unshallow
# Deepen an existing shallow clone
git fetch --deepen=50
# Check if a repo is shallow
git rev-parse --is-shallow-repository
# Shallow clone for CI (optimal)
git clone --depth 1 --single-branch -b main https://github.com/user/repo.git
# Fetch only tags with shallow clone
git fetch --depth 1 origin tag v1.0.0Use Cases
- Speeding up CI/CD pipeline cloning
- Working with monorepos locally
- Reducing bandwidth for large repositories
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Git Cherry-Pick Commits Example
Apply specific commits from one branch to another using cherry-pick with conflict resolution.
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.