Download a single folder or directory from a GitHub repo
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:
git@github.com: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.
Update Sep. 2016: there are a few tools created by the community that can do this for you:
GitZip (Credits to Kino - upvote his answer right here! )
DownGit (Credits to Minhas Kamal - upvote his answer right here! )
Git doesn't support this, but Github does 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.
Get the repo URL . First, copy the URL of the Github repo to your clipboard.
Modify the URL for subversion . I want to download the folder at /docs
from the master
branch, so I will append trunk/docs
. Full URL is now https://github.com/lodash/lodash/trunk/docs
. See my note below for a more in-depth explanation of why we must use this URL format.
Download the folder . Go to the command line and grab the folder with SVN. svn checkout https://github.com/lodash/lodash/trunk/docs
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:
master
branch, use trunk
instead. So the full path is trunk/foldername
foo
branch, use branches/foo
instead. The full path looks like branches/foo/foldername
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.
Two options for this feature:
Option 1: Browser Extensions
Chrome Extension, Firefox Addon
Usage:
Get Token:
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.
Go to DownGit > Enter Your URL > Download!
Now, you can DIRECTLY DOWNLOAD or create DOWNLOAD LINK for any GitHub public directory or file (specially large file) from DownGit! Here is a simple demonstration-
You may also configure the downloaded file's property- detailed usage.
链接地址: http://www.djcxy.com/p/27034.html上一篇: 带手势的图像
下一篇: 从GitHub仓库下载单个文件夹或目录