Lesson Completion
Back to course

Sparse Checkout

Intermediate
7 minutes4.7Git

The Hook (The "Byte-Sized" Intro)

Your monorepo has 50 projects. You work on one. Sparse checkout lets you clone the entire repo but only check out the files you need. Your working directory has 200 files instead of 200,000. git status runs in milliseconds. IDE indexing takes seconds, not minutes. Same repo, fraction of the files.

📖 What is Sparse Checkout?

Sparse checkout lets you select specific directories or files to include in your working directory while still having access to the full repository history.

Conceptual Clarity

Sparse checkout vs other approaches:

ApproachClones History?Checks Out All Files?Use When
Full clone✅ All✅ AllSmall repos
Shallow clone🟡 Partial history✅ AllQuick CI builds
Sparse checkout✅ All❌ Selected dirs onlyLarge repos, work on subset
Partial clone + sparse🟡 On-demand❌ Selected dirs onlyVery large repos

Two modes:

ModeHow It SelectsExample
Cone mode (default)By top-level directoriesapps/web/
Non-cone modeBy file patterns*.config.js

Real-Life Analogy

Sparse checkout is like a library card that only checks out certain sections. The full library exists, but your cart only has the science section. You can expand your card to include history whenever you want.

Visual Architecture

flowchart TD REPO["📦 Full Repository<br/>50 projects, 200K files"] --> SPARSE["🔍 Sparse Checkout"] SPARSE --> WORKING["📁 Working Directory<br/>1 project, 200 files"] SPARSE --> HIDDEN["👻 Other 49 projects<br/>Not checked out"] style REPO fill:#0f3460,stroke:#53d8fb,color:#53d8fb style WORKING fill:#1b2d1b,stroke:#53d8fb,color:#53d8fb style HIDDEN fill:#1a1a2e,stroke:#ffd700,color:#ffd700

Why It Matters

  • Speed: git status, IDE indexing, and file operations are dramatically faster.
  • Disk space: Only checked-out files consume disk space.
  • Focus: Your working directory contains only what you're working on.
  • Monorepo-friendly: Makes large monorepos viable for individual developers.

Code

bash
# ─── Enable sparse checkout on a new clone ─── git clone --sparse https://github.com/team/monorepo.git cd monorepo # ─── Add directories to checkout ─── git sparse-checkout set apps/web libs/shared-ui # Only apps/web/ and libs/shared-ui/ are checked out # ─── Add more directories later ─── git sparse-checkout add apps/api # ─── See what's included ─── git sparse-checkout list # apps/web # libs/shared-ui # apps/api # ─── Disable sparse checkout (get everything) ─── git sparse-checkout disable # ─── Combine with partial clone (best for very large repos) ─── git clone --filter=blob:none --sparse https://github.com/team/monorepo.git cd monorepo git sparse-checkout set apps/web # Blobs are fetched on-demand only for apps/web/

Key Takeaways

  • Sparse checkout lets you work with a subset of files from a large repo.
  • Use --sparse on clone + git sparse-checkout set to select directories.
  • Combine with --filter=blob:none for on-demand blob fetching in very large repos.
  • git sparse-checkout disable restores the full working directory.

Interview Prep

  • Q: What is sparse checkout and when would you use it? A: Sparse checkout lets you check out only specific directories from a repo while retaining access to the full history. Use it in large monorepos where you only need to work on a subset of projects.

  • Q: What is the difference between sparse checkout and shallow clone? A: Shallow clone limits history depth (fewer commits) but checks out all files. Sparse checkout keeps full history but limits which files/directories are checked out. They can be combined.

  • Q: What is a partial clone and how does it complement sparse checkout? A: A partial clone (--filter=blob:none) downloads commit and tree objects but fetches file contents (blobs) on demand. Combined with sparse checkout, it means you only download file data for the directories you're working in — ideal for very large repos.

Topics Covered

Large ReposPerformance

Tags

#git#sparse-checkout#large-repos#performance

Last Updated

2026-02-13