Git Sparse Checkout

Checkout only specific files or directories in a git repository

Git Sparse Checkout

Sparse checkout allows you to check out only a subset of files from the repository working copy. This is useful for large repositories where you only need to work on a specific part of the project.

Clone with sparse checkout

The most common way is to clone with sparse checkout enabled. This is where you specify the repository URL.

git clone --filter=blob:none --sparse <repository_url>
cd <repository_name>
git sparse-checkout set <dir_to_checkout>

Existing Repository

If you are already in a repository and want to enable sparse checkout:

git sparse-checkout init --cone

Set directories to checkout

Define which directories you want to include in your working copy:

git sparse-checkout set <dir1> <dir2> ...

Add directories

To add more directories to the current set:

git sparse-checkout add <dir3>

List current configuration

See what is currently checked out:

git sparse-checkout list

Disable sparse checkout

To return to a full checkout:

git sparse-checkout disable