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
Choosing the Right Option
Working with a huge repository
Less on disk vs less downloaded
| Command | Saves |
|---|---|
git sparse-checkout | Disk space and checkout time |
git clone --filter=blob:none | Download size (partial clone) |
git clone --depth 1 | History size (shallow clone) |
Examples
Keep one folder
git sparse-checkout set srcOnly src/ and top-level files.
Add a folder
git sparse-checkout add docsdocs/ comes back too.
Turn it off
git sparse-checkout disableEvery file again.
Workflow Examples
1
git clone --filter=blob:none --sparse <url>Clone lightly, sparse from the start
2
git sparse-checkout set webKeep 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.