sparse-checkout
- Git course
- Expert
- Lesson 14/32
- 4 min
Learn partial checkout with sparse-checkout.
What is sparse-checkout?
Sparse-checkout allows you to check out only selected directories or files from a large Git repository instead of populating the entire working directory. Other content remains in the Git repository but does not appear in the working directory.
git sparse-checkout init --cone
git sparse-checkout set frontend sharedThis feature helps keep unnecessary files out of the working area, especially in monorepos containing many projects.
Cone mode and selected directories
The git sparse-checkout init --cone command initializes directory-based sparse-checkout usage. You can then select which directories should appear in the working directory using the set command.
git sparse-checkout init --cone
git sparse-checkout set backend packagesYou can change the selection by running the same set command with different directories. Use git sparse-checkout list to view the current selection.
Practice Configure a partial working directory
First initialize sparse-checkout in cone mode. Then select only the frontend and packages directories. Finally, list the selection.
Starter code
# Sparse-checkout özelliğini başlat
# İstenen dizinleri seç
# Seçimi listeleSample solution
git sparse-checkout init --cone
git sparse-checkout set frontend packages
git sparse-checkout listExpected output
frontend packages
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command should a developer use to work only with the frontend and shared directories?
- git sparse-checkout add frontend shared
- git sparse-checkout init frontend shared
- git sparse-checkout set frontend shared Correct answer
- git sparse-checkout list frontend shared
Explanation: <code>git sparse-checkout set</code> specifies which directories should appear in the working directory.
2 List selected directories
git sparse-checkout ____
git sparse-checkout list
Explanation: The <code>list</code> command displays the directories selected by sparse-checkout.
3 Sparse-checkout commands
| Term | Meaning |
|---|---|
init --cone |
Initializes directory-based mode |
set |
Defines selected directories |
list |
Displays the selection |
disable |
Disables partial checkout |