bashbeginner

Git Shallow Clone for Large Repos

Shallow clone techniques to reduce download size by limiting commit history depth.

bash
# 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.0

Use 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.