Cloning only part of a Git monorepo

79 Views
English
#Git#monorepo#clone

What is a monorepo?

ext_1757057462508_img.png

A repository containing two or more logical projects (e.g., an iOS client and a web application).
These projects may be unrelated, loosely coupled, or connected by other means (e.g., through a dependency management tool).

A repository is large in several ways:

  • Number of commits
  • Number of branches and/or tags
  • Number of tracked files
  • Size of tracked content (measured by viewing the repository's .git directory)

 

Git sparse checkout

Cloning an entire Git repository, organized as a monorepo, is extremely inefficient.

Git provides a feature that allows you to retrieve only a portion of a repository. This allows for extremely efficient loading.

However, this only works with Git version 2.25 or later.

 

clone

Clone without files. Get only the git history without files.

git clone --filter=blob:none --no-checkout <GITHUB_URL>

 

spare init 

Enables sparse checkout feature.

git sparse-checkout init

 

sparse set

Specifies which directory to retrieve.

server/scheduler retrieves the scheduler directory within the server directory.

The same applies to client/android.

git clone --filter=blob:none --no-checkout <GITHUB_URL>

 

Then it is structured as follows:

.
├── .git/              <-- (Hidden folder where the actual Git data is stored)
└── client/
|   └── android/
|       ├── (Android project files and folders...)
|       └── ...
└── server/
    └── scheduler/
        ├── (Scheduler-related files and folders...)
        └── ...

set doesn't load anything, it just specifies what to load. The actual loading happens in checkout.

 

checkout

Actually download and set up the directory specified above.

git clone --filter=blob:none --no-checkout <GITHUB_URL>

Related Posts