git sparse-checkout

Workspaces & Large Projects

Check out only some folders of a large repository


The 'git sparse-checkout' command limits which folders are present on disk. Files outside those folders stay in every commit and in the repository, they are just not checked out — useful in huge repositories where you only work in one part. In the default cone mode, top-level files are always present. git status tells you what percentage of the files are on disk.

Synopsis

git sparse-checkout (set | add) <folder>...
git sparse-checkout list
git sparse-checkout disable
[ ] optional| or<arg> placeholder... repeatable--flag option

Options

Click any option to expand

Beginner (4)

Choose the folders to keep on disk (replaces the current list).

RecommendedPick the folders you work in

Example

git sparse-checkout set src

Add folders to the ones you keep.

RecommendedExtend the checkout without starting over

Example

git sparse-checkout add docs

Print the folders currently kept.

RecommendedCheck what is on disk

Example

git sparse-checkout list

Turn sparse checkout off and restore every file.

RecommendedReturn to a normal checkout

Example

git sparse-checkout disable

Choosing the Right Option

Working with a huge repository

Less on disk vs less downloaded

CommandSaves
git sparse-checkoutDisk space and checkout time
git clone --filter=blob:noneDownload size (partial clone)
git clone --depth 1History size (shallow clone)

Examples

Keep one folder

git sparse-checkout set src

Only src/ and top-level files.


Add a folder

git sparse-checkout add docs

docs/ comes back too.


Turn it off

git sparse-checkout disable

Every file again.

Workflow Examples

1
git clone --filter=blob:none --sparse <url>

Clone lightly, sparse from the start

2
git sparse-checkout set web

Keep just your folder

Troubleshooting

A folder is missing

Cause: It is outside the sparse checkout

git sparse-checkout add <folder>

Tips & Pitfalls

Best Practices

  • ✓Use cone mode (the default) — it is much faster than patterns.

Common Mistakes

  • ✗Thinking the hidden files are deleted from the project — they are still committed and pushed normally.

FAQ

A:

You do not see them, so you normally do not touch them; commits keep them unchanged.