my-git

Sparse Checkout

English 中文

Sparse checkout is used to keep only specific directories in the working tree.

It is suited for monorepos or large repositories: the repository contains many projects, but you currently only need a few directories.

Examples

Initialize cone mode:

git sparse-checkout init --cone

Only checkout specified directories:

git sparse-checkout set services/order services/payment

View current rules:

git sparse-checkout list

Restore complete working tree:

git sparse-checkout disable

Suitable Scenarios

Combining with Partial Clone

Sparse checkout controls which paths are present in the working tree.

Partial clone controls the object download strategy.

Using in combination:

git clone --filter=blob:none --sparse <url>
cd repo
git sparse-checkout set services/order

Considerations

Further Reading