bashbeginner
Git Shallow Clone for Large Repos
Shallow clone techniques to reduce download size by limiting commit history depth.
bashPress ⌘/Ctrl + Shift + C to copy
# 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.
bashadvanced
Git Sparse Checkout — Clone Only What You Need
Use sparse checkout to clone specific directories from large monorepos without downloading everything.
Best for: Working on a specific package in a monorepo
#git#sparse-checkout
bashintermediate
Git Hooks Pre Commit
Git workflow: git-hooks-pre-commit
Best for: version control
#git#version-control
bashadvanced
Git Hooks Post Commit
Git workflow: git-hooks-post-commit
Best for: version control
#git#version-control
bashadvanced
Git Lfs Large Files
Git workflow: git-lfs-large-files
Best for: version control
#git#version-control