Last Updated: May 11, 2021
·
79.39K
· janosgyerik

How to download a project subdirectory from GitHub

If you want to download an entire project from GitHub without version control data, you can use the Download ZIP option of the website. Alternatively, you could use command line tools, for example:

curl -L https://github.com/janosgyerik/jquery-upvote/tarball/master > project.tar.gz

What if you want to download only a subdirectory? The website doesn’t have an option for that, at least not yet. Not a problem! Thanks to Subversion support in GitHub, you could use the svn command line tool to that effect, for example:

svn export https://github.com/janosgyerik/jquery-upvote/trunk/lib jquery-upvote-lib

This creates a directory locally with the content of the specified subdirectory of the project.

Just make sure to construct the URL correctly, using the format:

https://github.com/USER/PROJECT/trunk/PATH DEST

Inspired by the question on #stackoverflow: git export from github remote repository

Related protips:

git checkout remote branch

5 Responses
Add your response

I don't have svn/git and don't plan to install either. I just want the subdirectory. What do I do?

over 1 year ago ·

@markjeronimus If I knew how to do it without svn, I would have answered that way... Unfortunately I don't :( So you have to either download the entire repo using GitHub's own download feature, or install svn to use this hack.

over 1 year ago ·

Finally I found what i need it really helped Thanks janosgyerik

over 1 year ago ·

Can we use this to download code from a particular branch from subdirectory??

over 1 year ago ·

For GitHub repos, you can clone any sub-directories of any GitHub repository (at any reference) using https://github.com/HR/github-clone

over 1 year ago ·