How to Use git sparse-checkout in Linux Terminal to Manage Massive Monorepos

Enterprise software organisations frequently house microservices, shared libraries, mobile applications, and backend infrastructure inside massive monolithic Git repositories (monorepos). Cloning such repositories using standard procedures downloads gigabytes of commit history and populates your local file system with hundreds of thousands of files you do not need, exhausting local drive capacity, slowing text editor indexing, and prolonging compilation times.

The native git sparse-checkout command solves this architectural challenge. Coupled with partial clone flags, sparse-checkout instructs Git to populate your local working tree with only the specific directories and files relevant to your current project, leaving the remainder of the monorepo lightweight and unmaterialised on disk.

Cloning a Monorepo with Blob Filtering and Cone Mode

To avoid downloading massive binary payloads and irrelevant directories when first cloning a monorepo:

  1. Perform a shallow or blobless clone with sparse checkout pre-initialised:
git clone --filter=blob:none --no-checkout https://github.com/example/massive-monorepo.git
  1. Navigate into the newly cloned project repository:
cd massive-monorepo
  1. Initialise sparse-checkout using cone mode (the high-performance default that validates directory patterns instead of full regular expressions):
git sparse-checkout init --cone

Defining Target Directories to Materialise on Disk

Once sparse-checkout is initialised, Git populates only top-level root files (such as README.md, .gitignore, and license files) by default. You can explicitly declare which directory trees to check out:

  1. To check out only a specific microservice folder:
git sparse-checkout set services/authentication-api
  1. To add complementary shared libraries without wiping your active directory selection, use the add flag:
git sparse-checkout add libs/common-crypto libs/database-client
  1. Verify the active checkout pattern registered inside your repository:
git sparse-checkout list
  1. Check out your target working branch (for example, main):
git checkout main

Git immediately fetches and writes only the files contained within your declared directories. All standard Git operations—including branching, staging, committing, and pushing—continue to function normally without conflicts.

Disabling Sparse-Checkout and Restoring the Full Repository

If you subsequently need access to the complete monorepo structure across all directories:

  1. Disable sparse-checkout mode:
git sparse-checkout disable

Git will pull down the remaining repository trees and restore the complete working directory across your workspace.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.