Monorepos with Git
A monorepo stores multiple projects or services in one Git repository. Companies like Google, Meta, Twitter, and Airbnb use monorepos. Git provides sparse checkout and submodules to manage complexity at scale.
01.Monorepo vs Polyrepo
Polyrepo: each project in its own repository. Pros: independent versioning, clear ownership, small focused repos. Cons: dependency management across repos is painful, cross-project refactors require multiple PRs, inconsistent tooling. Monorepo: all projects in one repo. Pros: atomic cross-project changes in one commit, shared tooling and CI, easier code reuse and refactoring. Cons: large repo size, more complex CI, requires tooling like Nx or Turborepo.
02.Git Tools for Large Monorepos
Sparse checkout: clone the whole repo but only check out the subset of directories you need โ dramatically reduces disk usage and clone time. Partial clone (--filter=blob:none): clone without file contents initially, download files on demand. Git LFS (Large File Storage): store large binary files like images and videos outside the main Git object store. Submodules: embed one repository inside another at a specific commit.
Commands
What is a key advantage of a monorepo over a polyrepo setup?