git sparse-checkout
git
Usage
git sparse-checkout set <dir>...Added in git 2.25, it keeps only the directories you name on disk; the history is still complete and cone mode takes directory names, not glob patterns.
Common flags
| Flag | Meaning |
|---|---|
| set <dir>... | check out only these directories |
| add <dir> | add another directory to the set |
| list | show the current set |
| disable | go back to a full checkout |
| reapply | apply the set again after a merge or pull |
| --no-cone | use raw gitignore-style patterns instead of directories |
Examples
git sparse-checkout set apps/web packages/uileaves the rest of the monorepo off your disk
git sparse-checkout listshows which directories are present
git sparse-checkout disablerestores every file
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git sparse-checkout do?
Added in git 2.25, it keeps only the directories you name on disk; the history is still complete and cone mode takes directory names, not glob patterns.
Q. How do I type it?
git sparse-checkout set <dir>... — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-sparse-checkout