Sub topic 1
Sparse Checkout for Monorepos: Why Large Monorepos Get Slow
Prerequisites
You should know basic Git commands such as clone, status, commit, and branch. You should also be comfortable using a command line and understand that a monorepo stores many projects in one repository.
Why large monorepos get slow
A monorepo can contain thousands of services, libraries, tests, and generated files. Git must manage this large file tree even when you work on one small service.
Large repositories can slow down several operations:
- A clone downloads repository data and usually creates every tracked file.
- A checkout changes many files when you switch branches.
git statuschecks whether files differ from the current commit.- Editors and build tools may scan directories that are unrelated to your work.
The cost depends on both the number of files and the size of their contents.
What Git stores versus what you see on disk
Git stores commits, trees, and file contents in its repository database. The working tree is the set of files currently written into your project directory.
These are different views:
| View | Purpose |
|---|---|
| Repository database | Stores history and versions |
| Working tree | Provides files for editing and building |
Sparse checkout limits the working tree. It does not normally remove the repository's commits or history. You can work with only selected directories while Git retains the broader repository structure.
> callout note > Sparse checkout saves working-tree space and file-system work. It is separate from a shallow clone, which limits commit history.
Sparse checkout in one command
Inside an existing clone, enable cone mode and select directories:
git sparse-checkout set --cone services/api libs/commonCone mode is Git's directory-oriented mode. The selected directories and their contents appear in the working tree. Root-level files are also included because many repositories need them for configuration.
Cone mode: choosing directories
Use cone mode when your work maps cleanly to whole directories. It is easier to understand and usually works well with Git tools.
For example, this selects one service:
git sparse-checkout set --cone services/apiFiles outside services/api remain tracked in the repository but are omitted from the working tree.
Exercise
Does cone-mode sparse checkout delete the other projects from repository history?
Show answer
No. It omits their files from the working tree while the repository still retains its history.