Explore Courses Blog Tutorials Interview Questions
+1 vote
in DevOps and Agile by (19.7k points)

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



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

svn co svn+ssh://[email protected]/home/admin/repos/finisht/static static

Is there a way to do this with Git?

1 Answer

+2 votes
by (62.9k points)

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

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

git init <repo>

cd <repo>

git remote add origin <url>

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.

For more information on frequently used commands visit git commands.

Browse Categories