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.
Navigate to the folder you want to download. Let's download /test
from master
branch.
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
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. The
full 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…