Freelance web and mobile developer - Edinburgh, UK

Download a Git subdirectory from GitHub

January 30, 2015

Have you ever needed to download only a subdirectory from a GitHub project without downloading the entire repository? Surprisingly, there doesn’t seem to be a way of doing this easily using Git. A somewhat unexpected solution is to use SVN.

First get the URL of the subfolder. GitHub URLs have the form:

https://github.com/author/repo-name/tree/master/subdirectory

Then replace /tree/master/ with /trunk/ to get:

https://github.com/author/repo/trunk/subdirectory

You can now download the subdirectory you’re interested in using SVN’s export command:

svn export https://github.com/author/repo/trunk/subdirectory

For example, this command will download a “Hello World” Chrome extension sample from GitHub:

svn export https://github.com/GoogleChrome/chrome-app-samples/trunk/samples/hello-world

Credit: Stack Overflow

Looking for an experienced full stack developer for your web or mobile project?
I'm available for contract work in Edinburgh and can also work remotely.