Partial SVN checkout and Git clone

Print Friendly, PDF & Email

Subversion had the (nice) feature of being to checkout only portion of a repository:

svn co $REPOURL/path/to/directory/

This is useful when you have one massive repository, but many “subprojects”. The usual Git correspondence is to have one repository for each “subproject” (so they aren’t really “sub” projects…). But the following may generate something similar (checking out a portion of the repository, and not cloning the entire history either), use sparse checkout and shallow clone features. The shallow clone cuts off the history and the sparse checkout only pulls the files matching your patterns [source]:

git init <repo>
cd <repo>
git remote add origin <url>
git config core.sparsecheckout true
echo "path/to/directory/*" >> .git/info/sparse-checkout
git pull --depth=1 origin master