Skip to content

Instantly share code, notes, and snippets.

@Niq1982
Last active June 9, 2017 10:26
Show Gist options
  • Save Niq1982/0171e8975db17b3153493b5dcd47aaba to your computer and use it in GitHub Desktop.
Save Niq1982/0171e8975db17b3153493b5dcd47aaba to your computer and use it in GitHub Desktop.
Clone only a part of a git project

Create empty repository and add origin without checkout:

mkdir <repo>
cd <repo>
git init
git remote add -f origin <url>

Set sparse checkout:

git config core.sparseCheckout true

Define which folders to check out in .git/info/sparse-checkout eg:

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

Then pull files from repository.

git pull origin master

You might want to include .gitignore files in your sparse-checkout -file, since the root files are not pulled from repository.

Instructions modified from a post in stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment