Back

Explore Courses Blog Tutorials Interview Questions
+4 votes
1 view
in DevOps and Agile by (29.3k points)
edited by

How can I download only a specific folder or directory from a remote Git repo hosted on GitHub?

Say the example GitHub repo lives here:

[email protected]:foobar/Test.git

Its directory structure:

Test/

    foo/ 

       a.py

       b.py

    bar/

       c.py

       d.py

I want to download only the foo folder and not clone the whole Test project.

1 Answer

+4 votes
by (50.2k points)
edited by

Git doesn't support this, but Github does via SVN. If you check out your code with subversion, Github will essentially convert the repo from git to subversion on the backend. There is a popular javascript library  'lodash' i will use this library as an example

1.copy the URL of git repo to your clipboard.

 https://github.com/lodash/lodash

2. Modify this url for subversion:

If you want to download the folder at /docs from the master branch, so you need to append trunk/docs. Full URL is now https://github.com/lodash/lodash/trunk/docs

3. Download that folder to the command line using:

svn checkout https://github.com/lodash/lodash/trunk/docs

Note: It may take up to 30 sec to convert large repositories.

For more commands like this please go through the following tutorial that will help you understand the git

Browse Categories

...