Git - Sparse Checkout

Dec 30, 2015 00:00 · 90 words · 1 minute read git github

The other day I wanted to checkout only part of a github repository, to be more specific, the Spark example subfolder of the kubernetes github repository: tree/master/examples/spark. I followed the instructions in this Stackoverflow answer: Create the folder where the repository code will be stored:

git init
git remote add -f origin git://github.com/kubernetes/kubernetes.git
Set core.sparseCheckout to true:
git config core.sparseCheckout true
and define which files should actually be checkout out:
echo "examples/spark" > .git/info/sparse-checkout
Finally update the (empty) repo with the state from the remote:
git pull origin master

Done!