Download a single folder or directory from a GitHub repo Download a single folder or directory from a GitHub repo git git

Download a single folder or directory from a GitHub repo


Update Apr. 2021: there are a few tools created by the community that can do this for you:

Note: if you're trying to download a large number of files, you may need to provide a token to these tools to avoid rate limiting.


Original (manual) approach: Checking out an individual directory is not supported by git natively, but Github can do this via SVN. If you checkout your code with subversion, Github will essentially convert the repo from git to subversion on the backend, then serve up the requested directory.

Here's how you can use this feature to download a specific folder. I'll use the popular javascript library lodash as an example.

  1. Navigate to the folder you want to download. Let's download /test from master branch.github repo URL example

  2. Modify the URL for subversion. Replace tree/master with trunk.

    https://github.com/lodash/lodash/tree/master/test

    https://github.com/lodash/lodash/trunk/test

  3. Download the folder. Go to the command line and grab the folder with SVN.

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

You might not see any activity immediately because Github takes up to 30 seconds to convert larger repositories, so be patient.

Full URL format explanation:

  • If you're interested in master branch, use trunk instead. So the full path is trunk/foldername
  • If you're interested in foo branch, use branches/foo instead. Thefull path looks like branches/foo/foldername
  • Protip: You can use svn ls to see available tags and branches before downloading if you wish

That's all! Github supports more subversion features as well, including support for committing and pushing changes.


Go to DownGit > Enter Your URL > Download!

You can DIRECTLY DOWNLOAD or create DOWNLOAD LINK for any GitHub public directory or file from DownGit. Here is a simple demonstration-


DownGit


You may also configure properties of the downloaded file- detailed usage.


Disclaimer: I fell into the same problem as the question-asker and could not find any proper solution. So, I created this tool for my own use first, then opened it for everyone :)


Two options for this feature:

Option 1: GitZip Browser Extension

Chrome Extension, Firefox Addon

Usage:

  1. In any GitHub repos page.
  2. Just double click on the blank part of the items you need.
  3. Click download button at bottom-right.
  4. See the progress dashboard and wait for browser trigger download.
  5. Get the ZIP file.

Get Token:

  1. Click GitZip Extension icon on your browser.
  2. Click "Normal" or "Private" link besides "Get Token".
  3. Authorize GitZip permission on Github auth page.
  4. Back to repo page of the beginning.
  5. Continue to use.

Option 2: Github gh-page

http://kinolien.github.io/gitzip by using GitHub API, and JSZip, FileSaver.js libraries.

Step1: Input github url to the field at the top-right.
Step2: Press enter or click download for download zip directly or click search for view the list of sub-folders and files.
Step3: Click "Download Zip File" or "Get File" button to get files.

In most cases, it works fine, except that the folder contains more than 1,000 files, because of the Github Trees API limitation. (refers to Github API#Contents)

And it also can support private/public repos and upgrade the rate limit, if you have GitHub account and use "get token" link in this site.