What Is Sparse Checkout?

Checkout only part of the entire repository. Focus on files you need.

Keep in mind: sparse-checkout settings are only kept in local copy. Won't be pushed. Won't be cloned.

Enable/Set/Add

git sparse-checkout set/add [--no-cone] <file(s)>

Running this will automatically enable sparse-checkout feature, which can be checked with git config --list .

Internally, sparse-checkout maintains two files:

  1. .git/config , where stores the feature ON/OFF flags
  2. .git/info/sparse-checkout . This file has a format the same as .gitignore but plays a whitelist role , and is the one set/add write to.

Alternatively, the user can edit .git/info/sparse-checkout manually. (See also: --cone (default flag) vs --no-cone)

List Current Settings

git sparse-checkout list

Disable/Re-enable

Disable

git sparse-checkout disable

: turn off all sparse-checkout flags in .git/config , but not touch .git/info/sparse-checkout .

Re-enable

git sparse-checkout add # no files here

: turn on flags, continue using current .git/info/sparse-checkout .

--cone (default flag) vs --no-cone

--cone is more like a "smart" mode:

--no-cone is somewhat "manual" mode:

In this mode, the user can filter anything without any restriction. But to remember: always set a path with a leading / like this: git sparse-checkout add /README.md /lua /doc .

If you have been aware of all of above, I suggest --no-cone mode, which is more flexible. An official discussion here .

Extra: Start From a Minimal Clone

git clone --filter=blob:none --no-checkout <URL> [<...>]
git sparse-checkout set [<...>]
git checkout

Reference

Published under Creative Commons Attribution-ShareAlike (CC-BY-SA) license. Feel free to share :)