The 2:00 AM Incident: Disk Full from a 45GB Monorepo
At 2:00 AM, the PagerDuty alert went off non-stop. The CI/CD runner executing a hotfix for the payment gateway abruptly halted because the /var disk partition hit 100%. Upon SSHing in to investigate, the culprit was immediately apparent: the company repository had ballooned to over 45GB with nearly 200,000 files. This was a shared monorepo housing mobile apps, a web portal, AI model pipelines, and more than 30 backend microservices.
Every time CI ran or a developer needed to spin up a quick test environment, Git would fetch the entire 45GB payload. The cloning process took nearly 25 minutes. Meanwhile, the engineer only needed to patch three lines of logic in the payment service. Customers were filing complaints over stuck transactions, and the server was paralyzed by zero remaining disk space. In that critical moment, the quickest lifesaver was enabling Git sparse-checkout alongside a blobless clone. The result: downloaded data dropped to under 350MB, completing the clone in just 18 seconds.
Under the Hood: How Git Sparse-Checkout Works
By default, whenever you run git checkout or git switch, Git populates the entire working tree from the target commit onto your disk. The more subprojects a repository contains, the more unused files your machine is burdened with. As a result, disk space vanishes rapidly and IDEs freeze up while indexing hundreds of thousands of files.
The Sparse-Checkout feature (revamped and heavily optimized starting in Git 2.25) allows you to define filters: populate only directories A and B onto disk, hiding everything else. Here are three key characteristics to keep in mind:
- Ultra-lean working tree: Your drive stores only the files you actually need to edit. IDEs open instantly, saving gigabytes of RAM otherwise wasted on indexing.
- Combined with blobless clone (
--filter=blob:none): Git downloads only commit history and tree metadata. File contents (blobs) from hidden directories are never fetched, maximizing bandwidth savings. - Preserves standard Git workflow: You can still branch, commit, push, rebase, or cherry-pick as usual. Git maintains full history integrity without breaking the shared repository structure.
Step-by-Step Setup in Real-World Environments
Below are hands-on commands you can directly apply to both developer workstations and CI/CD runners.
Step 1: Clone a Lightweight Repo with –filter and –sparse Flags
Instead of running a standard clone command, skip all content blobs and initialize sparse mode from the start:
# Download only commit history and tree metadata without fetching file contents yet
git clone --filter=blob:none --no-checkout https://github.com/company/super-monorepo.git
cd super-monorepo
This operation consumes only around 80MB to 150MB of bandwidth rather than pulling down the full 45GB monolith.
Step 2: Enable Cone Mode for Faster Directory Matching
Since Git 2.25, cone mode has been recommended by default. Rather than using regex to scan every file—which is excruciatingly slow in large repositories—cone mode checks directory path prefixes using optimized C code:
# Initialize sparse-checkout in cone mode
git sparse-checkout init --cone
At this point, the working directory remains completely clean, with no source code extracted yet.
Step 3: Specify Working Directories
Suppose you only need to modify the payment module services/payment-gateway and the shared library packages/shared-auth:
# Define the directories to retrieve
git sparse-checkout set services/payment-gateway packages/shared-auth
# Check out source code for the target branch
git checkout main
Immediately following the checkout command, only the two requested directories and root-level files (such as package.json or README.md) appear on your disk. All mobile app code and AI models remain absent from your local drive.
Step 4: Add Additional Directories While Debugging
While modifying code, if you need access to environment configurations in configs/production, you can quickly append them using the add subcommand:
# Check currently tracked directories
git sparse-checkout list
# Add the config directory without overwriting existing settings
git sparse-checkout add configs/production
Git will automatically fetch the blobs for the newly specified directory within seconds.
Step 5: Restore the Entire Repository When Needed
If you need to rebuild the entire monorepo to run final integration tests before release:
# Disable sparse-checkout to restore the entire repo
git sparse-checkout disable
Git will now synchronize the complete directory tree, just like a standard repository clone.
Summary
Managing massive monorepos requires strict resource optimization. Combining sparse-checkout with a blobless clone can cut CI/CD wait times by up to 90%, reclaim dozens of gigabytes of disk space, and keep developer workstations running smoothly.

