Summary - Monorepo
- Git course
- Expert
- Lesson 16/32
- 5 min
Combine monorepo tools to set up large repository management.
Combine monorepo management
A monorepo brings multiple projects together in one Git repository. In large repositories, you can use sparse-checkout to work with only the required directories and include other repositories using subtree or submodule.
git sparse-checkout init --cone
git sparse-checkout set frontend shared
git subtree add --prefix=vendor/tool \
https://example.com/tool.git mainThese tools address different needs: sparse-checkout limits the working area, while subtree and submodule include external repositories in the project.
Practice Use monorepo tools together
Initialize cone mode in a monorepo and select only the apps/web and packages/shared directories. Then add the main branch of https://example.com/utils.git as a subtree in the vendor/utils directory. Print an information message at the end.
Starter code
# Sparse-checkout modunu başlat
# Seçili proje dizinlerini belirle
# Harici depoyu subtree olarak ekle
# İşlem mesajını yazdırSample solution
git sparse-checkout init --cone
git sparse-checkout set apps/web packages/shared
git subtree add --prefix=vendor/utils https://example.com/utils.git main
echo 'Monorepo yapılandırması tamamlandı'Expected output
Monorepo yapılandırması tamamlandı
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 You want to work with selected project directories in a monorepo while linking another library as an independent repository. Which two tools are suitable together?
- Git bisect and Git blame
- Sparse-checkout and submodule Correct answer
- Git worktree and Git stash
- Subtree and Git merge
Explanation: Sparse-checkout checks out selected directories into the working area. A submodule links another repository to the main project as an independent repository reference.
2 Select the monorepo working area
git sparse-checkout init --cone
git sparse-checkout ____ frontend shared
git sparse-checkout init --cone
git sparse-checkout set frontend shared
Explanation: The <code>set</code> command specifies which directories are included in the monorepo working area.
3 Monorepo tool responsibilities
| Term | Meaning |
|---|---|
Monorepo |
Combines multiple projects |
Sparse-checkout |
Checks out selected directories |
Subtree |
Includes content in the main repository |
Submodule |
Creates an independent repository link |