Using Git sparse-checkout to slim monorepo clones
Learn how Git's sparse-checkout lets you clone only the directories you need from a large monorepo, reducing bandwidth and speeding up workflows.
13 Mar 2026, 10:29 UTC

Problem: cloning the whole monorepo
When a repository grows large, every developer must download the entire history and working tree even if they only need a subset of directories. This wastes bandwidth, slows down CI pipelines, and clutters local disks with files that are never touched.
Thesis: enable sparse-checkout
Git’s sparse-checkout feature (available since v2.25 and refined in v2.30+) lets you define exactly which paths should be materialized in your working tree. The repository’s full history remains accessible, but only the selected directories are checked out, reducing clone size and fetch time.
Worked example: setting up a sparse checkout
- Clone the repository with a blob filter and enable the sparse-checkout cone mode:
Where to run: any directory with read access to the remote. Permissions: read‑only access to the Git server is sufficient.git clone --filter=blob:none --sparse - After the clone finishes, specify the directories you want to appear locally. For example, to keep only
src/apiandsrc/web:
This writes the pattern togit sparse-checkout set src/api src/web.git/info/sparse-checkoutand immediately updates the working tree. - Verify that only the selected paths are present:
The output should list files undergit ls-filessrc/apiandsrc/weband nothing else. - Optionally, check that the object database is smaller than a full clone would be:
Compare this size to a baseline full clone (withoutdu -sh .git/objects--filter=blob:none --sparse) to see the reduction.
Trade‑off and maintenance
Sparse checkouts save space and speed, but they require the .git/info/sparse-checkout file to stay in sync with the directories developers actually need. If this file is edited incorrectly or not updated when new directories are added, expected files may be missing, leading to confusing build failures. Some Git commands (e.g., git submodule update --init, git clean -fdx) operate on the full working tree and may need explicit paths or the --sparse flag to avoid errors. Teams should document the sparse‑checkout pattern and treat the .git/info/sparse-checkout file as part of the project’s configuration—perhaps generating it from a template in the repository.
Actionable steps for teams
- Add the sparse‑checkout initialization to onboarding scripts or repository templates so new contributors get the correct pattern automatically.
- List the expected paths in
CONTRIBUTING.mdand explain how to update them when new directories are required. - Install a pre‑push hook that runs
git ls-filesand compares the output against the allowed set; abort the push if extra files are detected, preventing accidental full checkouts. - In CI pipelines, configure the checkout step to use the same
--filter=blob:none --sparseoptions and the defined sparse‑checkout set, ensuring consistent behavior across environments.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.