Tour of Git
Advanced Git / Lesson 5.15

Sparse Checkout & Partial Clones

Large repositories — especially monorepos — can contain thousands of directories and millions of files. If you only need a small part, downloading everything is wasteful. Sparse checkout and partial clone let you work with just the parts you need.

Sparse Checkout

Sparse checkout tells Git to only populate your working directory with specific directories or files. The rest of the repository's data is still in .git, but the files are not checked out.

Setting Up Sparse Checkout

# Initialize sparse checkout
git sparse-checkout init

# Choose which directories to include
git sparse-checkout set src/ docs/ README.md

After this, only src/, docs/, and README.md will appear in your working directory. Everything else is hidden.

Viewing and Modifying the Selection

# See what is currently checked out
git sparse-checkout list

# Add more directories
git sparse-checkout add tests/

# Reset to full checkout
git sparse-checkout disable

Cone Mode vs Non-Cone Mode

Sparse checkout has two modes:

Cone Mode (Default, Recommended)

git sparse-checkout init --cone
git sparse-checkout set src/frontend src/shared

Cone mode works with directory patterns only. It is faster and simpler — you specify directories, and Git includes all files within them.

Non-Cone Mode

git sparse-checkout init --no-cone

Non-cone mode supports arbitrary .gitignore-style patterns:

# .git/info/sparse-checkout
/*
!/*/
/src/
/docs/*.md

Non-cone mode is more flexible but slower, because Git must evaluate patterns against every file path.

AspectCone ModeNon-Cone Mode
Pattern typeDirectories onlygitignore-style patterns
PerformanceFastSlower on large repos
SimplicityEasy to understandComplex pattern syntax
RecommendationUse by defaultOnly when you need file-level patterns

Partial Clone

Sparse checkout controls which files appear in your working directory, but you still download all Git objects during git clone. Partial clone goes further — it skips downloading objects you do not need.

Blobless Clone

git clone --filter=blob:none https://github.com/example/large-repo.git

This downloads commits and trees but skips file contents (blobs). Git fetches blobs on demand when you check out files. This dramatically reduces initial clone time and disk usage.

Treeless Clone

git clone --filter=tree:0 https://github.com/example/large-repo.git

This skips both trees and blobs. Even faster, but some operations may trigger more on-demand fetches.

Combining Sparse Checkout with Partial Clone

The most efficient workflow for large repos combines both:

# 1. Partial clone — download only commit metadata
git clone --filter=blob:none --sparse https://github.com/example/monorepo.git
cd monorepo

# 2. Sparse checkout — select the directories you need
git sparse-checkout set services/auth libs/shared

# 3. Work normally — Git fetches blobs as needed
git log
git diff

This way you download only the data for the directories you actually work in.

Use Cases

  • Monorepos — a frontend developer checks out only frontend/ and shared/
  • Large repos — save disk space and clone time on repos with extensive history
  • CI/CD — build pipelines that only need specific directories
  • Onboarding — new developers get started faster with a focused checkout

Key Points

  • git sparse-checkout set <dirs> limits your working directory to specific directories
  • Cone mode (directories only) is simpler and faster than non-cone mode
  • git clone --filter=blob:none skips downloading file contents until needed
  • Combine sparse checkout with partial clone for the best performance on large repos
  • Use git sparse-checkout disable to return to a full checkout