Sparse Checkout: Materialize Only Needed Paths
Working directory scope
Extend the previous monorepo lesson: apps/web, apps/worker and apps/common.txt exist in one history. Sparse checkout changes which tracked paths appear on disk; it does not delete committed objects or restrict repository permissions. A sparse index is an additional representation optimization, not the same feature.
Cone mode selection
Start with a clean disposable full clone. Cone mode accepts directories, includes their descendants and includes files directly in leading directories and the repository root. Selecting apps/web leaves README.md and apps/common.txt present but omits apps/worker/worker.txt in the clean fixture. Check for valuable untracked and ignored files before changing scope; ignored files in excluded directories can be removed.
git status --short --ignoredgit sparse-checkout set --cone apps/webgit sparse-checkout listgit show HEAD:apps/worker/worker.txtExpand or restore scope
In a clean fixture, adding apps/worker extends the selection. Disabling sparse checkout returns the full tracked working directory. The commit and reachable object set remain unchanged. Local modifications, conflicts and ignored files can complicate real transitions; preserve valuable work instead of forcing removal.
git sparse-checkout add apps/workergit sparse-checkout disablegit status --shortPractice: visibility is not authorization
Predict whether Git can read the worker file while it is absent on disk. In a complete clone, git show can still read its committed bytes; the lab asserts that the reachable object set is identical. With a partial clone an omitted blob may need retrieval. Use repository permissions or separate repositories for confidentiality, never sparse checkout.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Sparse Checkout: Materialize Only Needed Paths — knowledge check
Distinguish storage, history, working tree and maintenance costs.
What does sparse checkout select?
In cone mode selecting apps/web, what else can remain?
Which command expands a cone selection?
Can an omitted file be read with git show in a complete clone?
Before changing a sparse selection, what should you preserve?