🔀 Git & GitHub Intermediate

What is git sparse-checkout?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

git sparse-checkout allows you to check out only a subset of files from a large repository, ignoring directories you don't need. Introduced for monorepos where a single repo contains many projects and you only need to work on one. Enable: git sparse-checkout init --cone — enable cone mode (faster, simpler pattern matching); git sparse-checkout set packages/frontend — only check out the frontend package; git sparse-checkout add packages/shared — also include shared; git sparse-checkout list — see current patterns; git sparse-checkout disable — revert to full checkout. Cone mode: matches top-level directories (recommended); Non-cone mode: full glob patterns like .gitignore. Combined with shallow clones for maximum speed in CI: git clone --depth=1 --filter=blob:none --sparse url; git sparse-checkout set path/to/service. This is used by large companies with giant monorepos (Google, Meta use custom tools built on this concept). Benefits: much faster checkouts, less disk space, better performance for tools that scan working directory (IDEs, linters). Practically useful when you have a monorepo with 100 packages and only need 3.

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Git & GitHub answers easy to follow.