Git : Sparse Checkout

Ever wanted to checkout part of a larger repository? This is possible with Sparse Checkout, which was a feature added with git@1.7.0. An experimental `sparse-checkout` command added with git@2.25.0.

A good article on the subject appears in the GitHub Blog - Bring your monorepo down to size with sparse-checkout by Derrick Stolee. The following is condensed from that article.

Let say we want to work with the story telling scripts in Ward's assets repository.

We start by cloning, using `--no-checkout` so we don't get all the files.

git clone --no-checkout https://github.com/WardCunningham/assets.git

cd assets

we then initialize sparse-checkout, and checkout the master branch.

git sparse-checkout init --cone git checkout master

We now have just the root directory, at this time we will just have the `.gitignore` file.

We can checkout story telling using

git sparse-checkout set /pages/story-telling