Git clone subdirectory-How do I clone a subdirectory only of a Git repository?

479    Asked by Yashraj in Python , Asked on Jul 2, 2021

I have my Git repository which, at the root, has two sub directories:

/finisht
/static

When this was in SVN, /finisht was checked out in one place, while /static was checked out elsewhere, like so:

svn co svn+ssh://admin@domain.com/home/admin/repos/finisht/static static

Is there a way to do this with Git?

Answered by yash Jaiteley

You can combine the sparse checkout and therefore the shallow clone options.

The shallow git clone subdirectory shuts off/cuts off the history and the sparse checkout only pulls the files matching your patterns.

git init 
cd
git remote add origin
git config core.sparsecheckout true
echo "finisht/*" >> .git/info/sparse-checkout
git pull --depth=1 origin master

Ensure that the minimum of git version of 1.9 is installed for this to work. Tested it myself only with 2.2.0 and 2.2.2. This way you will still be able to push, which isn't attainable with git archive.



Your Answer

Interviews

Parent Categories