You can download a file/folder from github
Simply use: svn export <repo>/trunk/<folder>
Ex: svn export https://github.com/lodash/lodash/trunk/docs
Note: You may first list the contents of the folder in terminal using svn ls <repo>/trunk/folder
(yes, that's svn here. apparently in 2016 you still need svn to simply download some github files)
Answer from Anona112 on Stack OverflowYou can download a file/folder from github
Simply use: svn export <repo>/trunk/<folder>
Ex: svn export https://github.com/lodash/lodash/trunk/docs
Note: You may first list the contents of the folder in terminal using svn ls <repo>/trunk/folder
(yes, that's svn here. apparently in 2016 you still need svn to simply download some github files)
You can use Github Contents API to get an archive link and tar to retrieve a specified folder.
Command line:
curl https://codeload.github.com/[owner]/[repo]/tar.gz/master | \ tar -xz --strip=2 [repo]-master/[folder_path]
For example,
if you want to download examples/with-apollo/ folder from zeit/next.js, you can type this:
curl https://codeload.github.com/zeit/next.js/tar.gz/master | \
tar -xz --strip=2 next.js-master/examples/with-apollo
git - Shortest way to download from GitHub - Unix & Linux Stack Exchange
git - Download specific files from github in command line, not clone the entire repo - Stack Overflow
Plain and simple: How to download files from github?
Download files from Github without Git using PowerShell
Videos
Update April 2021: there are a few tools created by the community that can do this for you:
- Download Directory (Credits to fregante)
- It has also been integrated into the excellent Refined GitHub Chrome extension as a button in the GitHub web user interface.
- GitZip (Credits to Kino—see his answer here)
- DownGit (Credits to Minhas Kamal—see his answer here)
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 Subversion (SVN). If you checkout your code with Subversion, GitHub will essentially convert the repository from Git to Subversion on the backend, and then serve up the requested directory.
Update November 2024: The Subversion support has been removed after January 8, 2024: https://github.blog/news-insights/product-news/sunsetting-subversion-support/. The rest of this answer is outdated and describes the functionality in the past.
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
/testfrommasterbranch.
Modify the URL for subversion. Replace
tree/masterwithtrunk.https://github.com/lodash/lodash/tree/master/test➜https://github.com/lodash/lodash/trunk/testDownload 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
masterbranch, usetrunkinstead. So the full path istrunk/foldername- If you're interested in
foobranch, usebranches/fooinstead. The full path looks likebranches/foo/foldername- Pro tip: You can use
svn lsto 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:

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 simple solution. So, I developed this tool for my own use first, and then opened it for everyone :)
The shortest way that seems to be what you want would be git clone https://github.com/user/repository --depth 1 --branch=master ~/dir-name. This will only copy the master branch, it will copy as little extra information as possible, and it will store it in ~/dir-name.
This will clone the files into new directory it creates:
git clone [email protected]:whatever NonExistentNewFolderName
Copy the specific file's raw link from GitHub.(As you open the file in Github, on the top right corner you can see the option to open the file in raw mode. Open it in raw mode and copy the URL)
Now use curl or wget command in command line to download the file.
curl -o filename raw-link-to-file
or
wget -O filename raw-link-to-file
Please note that
If you go to the page and view the links provided by "raw" (in the top left corner, when viewing the file). You will see, that you can access it by:
https://github.com/username/repository/raw/$changeset_hash/path/to/file
Instead of $changeset_hash you can also provide a branch (e.g. master) or tag.
You can retrieve the raw file using something like wget.
Accessing a single file directly from a .git-repository is not possible (as far as I know), because of how the data is stored.
edit: When you want to access a file from a private repo, you first have to create an access token with the appropriate permissions in your account settings. Instead of calling the url above you can then use github's API to access the content of a file. Be sure to use the Accept-header for custom media types to get the raw data. This might look something like this:
curl \
-H 'Authorization: token $YOUR_TOKEN' \
-H 'Accept: application/vnd.github.v3.raw' \
-O \
-L 'https://api.github.com/repos/:owner/:repo/contents/:path'
The -O will save the contents in a local file with the same name as the remote file name. For easier use you can wrap it in a script. @Chris_Withers suggested an edit with a nice python snippet that unfortunately got rejected as to big of a change to the answer.
It does work, if you use the correct URL.
For a GitHub repo, there's a zip at https://github.com/<user>/<repo>/archive/<branch>.zip, so you can download it with:
wget https://github.com/<user>/<repo>/archive/<branch>.zip
This downloads the zipped repo for a given branch. Note that you can also replace the branch by a commit hash.
Using cURL
curl -L -O https://github.com/<user>/<repo>/archive/<branch>.zip
cURL's -L flag follows redirects - it's a default in wget. -O is advised by Phil Gibbins in a comment.
Download a .tgz instead of .zip
You can also download a tarball with:
wget https://github.com/<user>/<repo>/archive/<branch>.tar.gz
From the comments I saw you actually speak about GitHub.
It won't work like this because:
Downloading a project on GitHub causes the GitHub server to first pack your project as zip and than forwarding you to a temporary link where you get your zip ..
this link will only work for a certain time and than GitHub will delete your zip file from their servers..
So what you get with wget is just the html page which would forward you as soon as your zip file is generated.
As suggested use
git clone http://github.com/<yourRepoLink> <optional local path where to store>
to download the git repo ... If for some reason (e.g. for transfer it to others) you need it explicitly as zip you still could pack it after cloning is finished..