← All languages
Git command of the day
Random

sparse-checkout

Reduce the working tree to a subset of tracked files.

Description

The git sparse-checkout command configures the sparse-checkout feature, which allows you to have only a subset of files from the repository present in your working directory. This is extremely useful for large monorepos where you only need to work with specific directories.

With sparse-checkout enabled, Git will only populate the working tree with files that match the specified patterns or directories. Other files remain in the repository and are tracked normally, but they do not appear in the working directory, saving disk space and reducing clutter.

The cone mode (default since Git 2.37) provides a simplified pattern syntax optimized for directory-based sparse checkouts. In cone mode, you specify directories to include, and Git efficiently determines which files to materialize.

Arguments

NameDescriptionOptional
init Enable the sparse-checkout feature and set the initial patterns. Yes
set Set the sparse-checkout patterns to the given list of directories or patterns. Yes
add Add directories or patterns to the existing sparse-checkout definition. Yes
list List the directories or patterns in the current sparse-checkout definition. Yes

Example

git sparse-checkout init --cone
git sparse-checkout set src/ docs/
git sparse-checkout add tests/
git sparse-checkout list

Reference