CodeBlanks Logo Icon CodeBlanks

sparse-checkout

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 shared

This 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 packages

You 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

terminal
# Sparse-checkout özelliğini başlat
# İstenen dizinleri seç
# Seçimi listele

Sample solution

terminal
git sparse-checkout init --cone
git sparse-checkout set frontend packages
git sparse-checkout list

Expected 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

Question
git sparse-checkout ____
Answer
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

All lessons in Expert