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.
Just to amplify the answers above, a real example from a real GitHub repository to a local directory would be:
Sometimes a concrete example helps clarify the substitutions proposed.
You cannot; unlike Subversion, where each subdirectory can be checked out individually, Git operates on a whole-repository basis.
For projects where finer-grained access is necessary, you can use submodules -- each submodule is a separate Git project, and thus can be cloned individually.
It is conceivable that a Git front-end (e.g. GitHub's web interface, or gitweb) could choose to provide an interface for you to extract a given folder, but to my knowledge none of them do that (though they do let you download individual files, so if the folder does not contain too many files, that is an option)
Edit - GitHub actually offers access via SVN, which would allow you to do just this (as per comment). See https://github.com/blog/1438-improved-svn-here-to-stay-old-svn-going-away for latest instructions on how to do this
If the directoy you want to download is a separated library, it's better to create an other git repo, and then to use the git submodule function.
Of course, you have to be the owner of the initial repo you want
Nothing wrong with other answers but I just thought I'd share step-by-step instructions for those wandering through this process for the first time.
How to download a single folder from a github repository (Mac OS X):
BTW - If you are on Windows or some other platform you can find a binary download of subversion (svn) at http://subversion.apache.org
Update
Regarding the comment on resuming an interrupted download/checkout. I would try running
svn cleanup
followed bysvn update
. Please search SO for additional options.Our team wrote a bash script to do this because we didn't want to have to install SVN on our bare bones server.
https://github.com/ojbc/docker/blob/master/java8-karaf3/files/git-download.sh
It uses the github API and can be run from the command line like this:
If you have
svn
, you can usesvn export
to do this:Notice the URL format:
https://github.com/
/trunk
appended at the endBefore you run
svn export
, it's good to first verify the content of the directory with: