Sparse Checkout

Table of contents
  1. Monorepo
  2. Checkout only the necessary folders
  3. Check the status

Monorepo

A monorepo a single repository that contains multiple logical root directories or microservices (e.g. frontend subfolder and a backend subfolder.)

As a monorepo grows in size, tracking can become slow.

However, a frontend developer may not have to consistently pull and push with the changes in a backend folder and vice versa.

We don’t need them, so why keep them?

If the logics of difference microservices can be isolated, version control can prune down unnecessary structures.


Checkout only the necessary folders

First clone a project without checking them out:

git clone <URL> --no-checkout
# For efficient cloning use partial clone
git clone <URL> --no-checkout --filter=blob:none
# Or if you also don't need the commit history
git clone <URL> --no-checkout --depth 1

cd into the cloned project and init only the root files:

git sparse-checkout init --cone

Yes it is --cone not a typo of --clone.

Set subfolders that you’d like to checkout:

git sparse-checkout set backend db/config

Then checkout:

git checkout

Check the status

Try:

git status

Now your git status will indicate that you are in sparse checkout mode.

You will see that your project is still up to date with the remote even though all the other subfolders are not locally present.


References: