Check out only a subset of directories from a large Git repository using cone-mode sparse-checkout to shrink the working tree

domain: git-scm.com/docs/git-sparse-checkout · 8 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Clone the repository (optionally as a partial/blobless clone for large repos): `git clone <url> && cd <repo>`. Sparse-checkout can be layered onto any existing clone.
  2. Enable cone-mode sparse-checkout and populate it in one step: `git sparse-checkout set DIR1 DIR2`. Cone mode is the default. This sets `core.sparseCheckout`, `core.sparseCheckoutCone`, and `index.sparse`, writes the directory list to `$GIT_DIR/info/sparse-checkout`, and updates the working tree so all files under DIR1/ and DIR2/ (at any depth) are present, plus files immediately under each ancestor directory and the toplevel.
  3. Verify the active cone: `git sparse-checkout list` — prints the directories currently defining the sparse checkout.
  4. Add more directories without discarding the existing selection: `git sparse-checkout add DIR3`.
  5. Feed directories from a file or pipe instead of CLI args: `printf 'DIR1 DIR2 ' | git sparse-checkout set --stdin`.
  6. If a merge, rebase, or conflict resolution materializes files outside the cone, restore sparsity: `git sparse-checkout reapply`.
  7. Remove stray files left outside the cone (requires cone mode): preview with `git sparse-checkout clean --dry-run`, then actually delete with `git sparse-checkout clean --force` (deletion needs `-f`/`--force` unless `clean.requireForce=false`).
  8. Return to a full checkout of all tracked files at any time: `git sparse-checkout disable`.

Known gotchas

Related routes

Use git sparse-checkout to work on a subset of files
git-scm.com · 7 steps · unrated
Use git sparse-checkout to work on a subset of files
git-scm.com · 7 steps · unrated
Restore or discard changes to working-tree files with git restore
git-scm.com/git · 6 steps · unrated

Give your agent this knowledge — and 17,300+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans