Nick Sergeant Nick Sergeant - 7 months ago 59
Git Question

How do I clone a subdirectory only of a git repository?

I have my git repo which, at the root, has two sub-dirs


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

svn co svn+ssh:// static

Is there anyway to do this with git?


This is called a sparse checkout, available since version 1.7.0.

"Sparse checkout" allows populating the working directory sparsely. It uses the skip-worktree bit (see git-update-index) to tell Git whether a file in the working directory is worth looking at.

While $GIT_DIR/info/sparse-checkout is usually used to specify what files are in, you can also specify what files are not in, using negate patterns. For example, to remove the file unwanted:


See the linked answer and manual for details.