bashadvanced
Git Sparse Checkout — Clone Only What You Need
Use sparse checkout to clone specific directories from large monorepos without downloading everything.
bashPress ⌘/Ctrl + Shift + C to copy
# Clone with sparse checkout (no working tree initially)
git clone --filter=blob:none --sparse https://github.com/org/monorepo.git
cd monorepo
# Initialize sparse-checkout in cone mode (recommended)
git sparse-checkout init --cone
# Add directories you need
git sparse-checkout set packages/shared packages/frontend
# Add more directories later
git sparse-checkout add packages/backend
# View current sparse-checkout patterns
git sparse-checkout list
# packages/shared
# packages/frontend
# packages/backend
# Disable sparse checkout (restore full working tree)
git sparse-checkout disable
# --- Non-cone mode (pattern-based) ---
git sparse-checkout init --no-cone
git sparse-checkout set '!/*' '/README.md' '/packages/api/**'
# ! excludes everything first, then includes specific patterns
# Check what's checked out vs excluded
git ls-tree -r HEAD --name-only | head -20
# Partial clone + sparse = fastest monorepo experience
git clone --filter=blob:none --sparse --depth=1 \
https://github.com/org/monorepo.gitUse Cases
- Working on a specific package in a monorepo
- Reducing CI clone times for large repositories
- Contributing to specific subdirectories of OSS projects
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
bashbeginner
Git Shallow Clone for Large Repos
Shallow clone techniques to reduce download size by limiting commit history depth.
Best for: Speeding up CI/CD pipeline cloning
#git#shallow-clone
bashadvanced
Git Submodule Management
Add, update, and manage Git submodules for including external repositories in your project.
Best for: Including shared libraries across multiple repos
#git#submodules
bashadvanced
Git Subtree Workflow
Use git subtree to include external repositories as subdirectories without submodule complexity.
Best for: Including shared code without submodule complexity
#git#subtree
bashadvanced
Git Submodules — Add, Update, and Pin
Manage repository dependencies with submodules: add, update, pin versions, and handle nested repos.
Best for: Sharing code libraries across multiple repos
#git#submodule