git:checkout部分目录, sparse checkout

1
2
3
git init <repo>
cd <repo>
git remote add -f origin <url>

This creates an empty repository with your remote. Then do:

1
git config core.sparsecheckout true

Now you need to define which files/folders you want to actually check out. This is done by listing them in .git/info/sparse-checkout, eg:

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

Last but not least, update your empty repo with the state from the remote:

1
git pull origin master