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 `--sparse`, which starts with only the files in the root of the repository. man page

git clone --sparse 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 add story telling to the selection of files we have checked out, using:

git sparse-checkout add /pages/story-telling