Home·Terminal commands

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

FlagMeaning
set <dir>...check out only these directories
add <dir>add another directory to the set
listshow the current set
disablego back to a full checkout
reapplyapply the set again after a merge or pull
--no-coneuse raw gitignore-style patterns instead of directories

Examples

git sparse-checkout set apps/web packages/ui

leaves the rest of the monorepo off your disk

git sparse-checkout list

shows which directories are present

git sparse-checkout disable

restores 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