MacBook Pro affichant un éditeur de code

Git how to check only a folder – Sparse checkout

Since git 1.7.0 it is possible to use a technique called sparse checkout

The steps for cloning are:

Mkdir<repo></repo>
Cd<repo></repo>
git init
git remote add -f origin<url></url>

This creates an empty folder, runs the fetches but without checking out the files. Then you have to configure git to use sparseCheckout.

git config core.sparseCheckout true

Then you have to define which folders/files should be present. To do this you have to add them in the file .git/info/sparse-checkout. For example:

echo "some/dir/" .git/info/sparse-checkout
echo "another/sub/tree" - .git/info/sparse-checkout

Once this is done, you have to update the folder:

git sweater origin master

sparse checkout documentation.

Leave a comment