Progress:
TIER 1 · MODULE 34· Basics

git sparse-checkout

Make huge repos workable on small disks.

🎯 What & why

Materialize only some directories of the repo into the working tree. The rest exists in .git/ but isn't checked out. Essential for huge monorepos.

🧠 Mental model

Sparse-checkout configures the skip-worktree bit on index entries you don't want materialized. The object DB stays complete; the working tree is partial. Two modes: cone (directory-prefix matching, fast) and non-cone (full pathspec, more flexible).

🛠️ Synopsis

git sparse-checkout (init|list|set|add|reapply|disable|check-rules) [<options>]

🎚️ Switches & options

FlagWhat it does
init [--cone]Enable sparse-checkout with cone mode (recommended).
set <patterns>...Define which paths to include.
add <patterns>...Add to the existing pattern set.
listShow current patterns.
disableRestore full checkout.

📦 Subcommands

init [--cone] — Enable sparse-checkout. Cone mode is faster and recommended.
$ git sparse-checkout init --cone
set <patterns>... — Replace the include set.
$ git sparse-checkout set src/ docs/
add <patterns>... — Append to the existing include set.
$ git sparse-checkout add tests/
list — Show current patterns.
$ git sparse-checkout list
reapply — Re-evaluate skip-worktree bits after .gitattributes changes.
$ git sparse-checkout reapply
disable — Restore a full checkout.
$ git sparse-checkout disable
check-rules — Test patterns against paths read from stdin.
$ echo 'src/main.c' | git sparse-checkout check-rules

💡 Use cases

🧪 Examples

Initialize and check out only two directories.
$ git sparse-checkout init --cone
$ git sparse-checkout set src/ docs/
Add another directory.
$ git sparse-checkout add tests/
Disable and restore everything.
$ git sparse-checkout disable

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.