Skip to content

Instantly share code, notes, and snippets.

View rubenqba's full-sized avatar

Rubén Bressler rubenqba

View GitHub Profile

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

When cloning a Git repository, you acquire all files contained within that repository. However, often we are only interested in a small subset of files and/or directories, thus having the entire repository can be overwhelming.

Nevertheless, since Git v1.7.0, a feature called Sparse Checkout was introduced to address this issue. Spase checkout which change the working tree from having all tracked files present to only having a subset of those files. It can also switch which subset of files are present, or undo and go back to having all tracked files present in the working copy.

The steps to do a sparse clone are as follows:

mkdir