[git] Download single files from GitHub

I guess most of you, developers, use any VCS, and I hope some of you use Git. Do you have any tip or trick how to get a download URL for a single file in a repository?

I don't want the URL for displaying the raw file; in case of binaries it's for nothing.

http://support.github.com/discussions/feature-requests/41-download-single-file

Is it even possible to use GitHub as a "download server"?

If we decide to switch to Google Code, is the mentioned functionality presented here?

Or is there any free-of-charge hosting and VCS for open-source projects?

This question is related to git version-control github

The answer is


  1. The page you linked to answers the first question.

  2. GitHub also has a download facility for things like releases.

  3. Google Code does not have Git at all.

  4. GitHub, Google Code and SourceForge, just to start, are free hosting. SourceForge might still do CVS.


GitHub Releases feature

Rather than link to download a specific file within the repo, you should use GitHub's Releases feature to associate downloadable data (such as compiled binaries) with the tagged version of the source code used to generate that data.

https://github.com/blog/1547-release-your-software

We're excited to announce Releases, a workflow for shipping software to end users. Releases are first-class objects with changelogs and binary assets that present a full project history beyond Git artifacts.

Releases are accompanied by release notes and links to download the software or source code.

Following the conventions of many Git projects, releases are tied to Git tags. You can use an existing tag, or let releases create the tag when it's published.

enter image description here


To follow up with what thomasfuchs said but instead for GitHub Enterprise users here's what you can use.

curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept: application/vnd.github.v3.raw' -O -L https://your_domain/api/v3/repos/owner/repo/contents/path

Also here's the API documentation https://developer.github.com/v3/repos/contents


You can use curl this way:

curl -OL https://raw.githubusercontent.com/<username>/<repo-name>/<branch-name>/path/to/file

O means that curl downloads the content
L means that curl follows the redirection


Go to the script and click "Raw"

Then copy the link and download it with the aria2c link.

Eg: aria2c https://raw.githubusercontent.com/kodamail/gscript/master/color.gsf

Trick: the file I wanted to download is, https://github.com/kodamail/gscript*/blob*/master/color.gsf

just modify the link into https://raw.githubusercontent.com/kodamail/gscript/master/color.gsf

Remove the italic texts and add bold texts in the same format, it will give you the right link.

which can be used with aria2c,wget or with curl, I used aria2c here.


  1. Go to the file you want to download.
  2. Click it to view the contents within the GitHub UI.
  3. In the top right, right click the Raw button.
  4. Save as...

If you happen to use curl and firefox... you could use the cliget add-on which generates a curl call including all authentication mechanisms (aka cookies).

So right click on the raw button cliget->"copy url for link" and then paste that into a shell. You will get your file even if you had to log-in to see it.


You can try github-files-fetcher, it is a command line tool which downloads a single folder or file from a GitHub repo.

Think a real scenario: you were visiting the following webpage page and wanna download the async subdirectory alone.

https://github.com/reduxjs/redux/tree/master/examples

sorry for not being allowed to post images.

With The github-files-fetcher, you should first copy the url of that page, which is https://github.com/reduxjs/redux/tree/master/examples/async, and then run the command below in command line:

fetcher --url=https://github.com/reduxjs/redux/tree/master/examples/async


This method works for Windows as I have never used MAC so I don't know what are the alternate keys in MAC for the keys which I'm going to mention below.

Let's talk about the CSV files. IF you want to download the CSV file:

  1. Go to that particular dataset that you want to download and click on it.
  2. You will see "Raw" button on the top right side of the dataset.
  3. Press "Alt" and then left click the "Raw" button.
  4. The whole CSV will download in your system.

Remeber, you have to press Alt and left click simultaneously. Just clicking the "Raw" button will open up the CSV in the browser.

I hope that helps.


For users with GitHub Enterprise you need to construct URL in following scheme

Invoke-WebRequest http://github.mycompany.com/api/v3/repos/my-org/my-repo/contents/myfiles/file.txt -Headers @{"Authorization"="token 8d795936d2c1b2806587719b9b6456bd16549ad8"}

Details can be found here

http://artisticcheese.blogspot.com/2017/04/how-to-download-individual-files-from.html


Go to DownGit - Enter Your URL - Simply Download

No need to install anything or follow complex instructions; specially suited for large source files.

Disclaimer: I am the author of this tool.


Download with DownGit


You can download individual files and directories as zip. You can also create download link, and even give name to the zip file. Detailed usage- here.


My simple way to do it is:

  1. click the 'Raw' button to get the file contents of github_csv.csv shown on the browser.
  2. Then create file.csv and open it in a text editor like notepad
  3. Then copy the file content from the website and paste it on the file.csv
  4. Your file.csv is github_csv.csv

This is now possible in GitHub for any file. You need to translate your files for raw.github.com. For example, if your file is in your repository at:

https://github.com/<username>/<repo>/some_directory/file.rb

Using wget you can grab the raw file from:

https://raw.github.com/<username>/<repo>/<branch>/some_directory/file.rb

Rails Composer is a great example of this.


  1. On github, open the file you want to download
  2. Locate the "Raw" button adjacent to the "Blame" button
  3. Press "Alt" on your keyboard and left-click on your mouse at the same time
  4. The file will download automatically in a ".txt" format (it did for me)
  5. Change the ".txt" extension to ".csv" extension manually

This worked for me and I hope it does for you too.


2019 Summary

There are a variety of ways to handle this, depending on how large the file is, whether or not you need to download folders in addition to files, and if you plan to do this manually or programmatically.

There are six options summarized below. And for those that prefer a more hands-on explanation, I've put together a YouTube video: Download Individual Files and Folders from GitHub.

Also, I've posted a similar answer on StackOverflow for those that need to download single folders/directories from GitHub (as opposed to files).


1. GitHub User Interface

  • There's a download button on most images.
  • There's a download button on the repository's homepage. Of course, this downloads the entire repo, after which you would need to unzip the download and then manually drag out the specific files you need.

2. Browser Context Menu

  • Go to the file on GitHub, right click on the "Raw" button to open the browser's context menu. From there, if you're using Google Chrome, select "Save Link As...". Other browser's will have a similar UI, but the selection description may vary. For example, it will be listed as "Download Linked File" and "Download Linked File As" on Safari.

3. Third Party Tools

  • There are a variety of browser extensions and web apps that can handle this, with DownGit being one of them. Simply paste in the GitHub URL to the file and press the "Download" button. Note that the link should be the GitHub.com hosted repository view, as opposed to the direct file link. File link example: https://github.com/babel/babel-eslint/blob/master/lib/parse.js.

4. Subversion

  • GitHub does not support git-archive (the git feature that would allow us to download specific files). GitHub does however, support a variety of Subversion features, one of which we can use for this purpose. Subversion is a version control system (an alternative to git). You'll need Subversion installed. Grab the GitHub URL for the file you want to download. You'll need to modify this URL, though. You want the link to the repository, followed by the word "trunk", and ending with the path to the nested file. In other words, using the same file link that I mentioned above, we would replace "blob/master" with "trunk". Finally, open up a terminal, navigate to the directory that you want the content to get downloaded to, type in the following command (replacing the URL with the URL you constructed): svn export https://github.com/babel/babel-eslint/trunk/lib/parse.js, and press enter.

5. cURL

  • You'll need cURL installed. Go to the file on GitHub.com, left click on the "Raw" button to get to the direct file link, copy this URL, open a terminal, navigate to the directory that you want the content to get downloaded to, type in the following command, replacing the filename with whatever you want to name it, and replacing the URL with the one you just copied: curl -o parse.js https://raw.githubusercontent.com/babel/babel-eslint/master/lib/parse.js.

6. GitHub API

  • This is actually what DownGit is using under the hood. Using GitHub's REST API, make a GET request to the content endpoint. The endpoint can be constructed as follows: https://api.github.com/repos/:owner/:repo/contents/:path. After replacing the placeholders, an example endpoint is: https://api.github.com/repos/babel/babel-eslint/contents/lib/parse.js. This gives you JSON data for that file, including a download URL (the same download URL that we used in the cURL example above). This method isn't all that useful for a single file, though (you'd be more likely to use it for downloading a specific folder, as detailed in the answer that I linked to above).

This is what worked for me just now...

  1. Open the raw file in a seperate tab.

  2. Copy the whole thing in your notepad in a new file.

  3. Save the file in the extension it originally had

tested with a php file that i downloaded just now (at time of answer)


GitHub Mate makes single file download effortless, just click the icon to download, currently it only work on Chrome.

GitHub Mate Download


To download a file from a Github repo, use the 'curl' command with the link to the raw file.

curl https://raw.githubusercontent.com/user/repo/filename --output filename

Add the --output option followed by the new filename to download the raw file to the newly created file.


Or try this

const https = require('https');
const fs = require('fs');
const DOMAIN = 'raw.githubusercontent.com';

function writeFile(data, fileName) {
  fs.appendFile(fileName, data.toString(), err => {
    if (err) {
      console.log('error in writing file', err);
    }
  });
}

function EOF(data) {
  console.log('EOF');
}

function getFileName(pathToFile) {
  var result = pathToFile.split('/');
  var splitLength = result.length;
  return result[splitLength - 1];
}
function getFile(branchName, username, repoName, ...pathToFile) {
  pathToFile.forEach(item => {
    const path = `/${username}/${repoName}/${branchName}/${item}`;
    const URL = `${DOMAIN}${path}`;
    const options = {
      hostname: DOMAIN,
      path: path
    };
    var fileName = getFileName(item);

    https
      .get(options, function(res) {
        console.log(res.statusCode);
        /* if file not found */
        if (res.statusCode === 404) {
          console.log('FILE NOT FOUND');
        } else {
          /* if file found */
          res.on('data', data => writeFile(data, fileName));
          res.on('end', data => EOF(data));
        }
      })
      .on('error', function(res) {
        console.log('error in reading URL');
      });
  });
}
getFile('master', 'bansalAyush', 'InstagramClone', '.babelrc', 'README.md');

You should just do it with the raw URL of your file.

For example to download the README of AFNetworking:

curl https://raw.githubusercontent.com/AFNetworking/AFNetworking/master/README.md > ADREADME.md 

As it is a public repo you don't need any credentials. Please note the kind of url: raw.githubusercontent.com/path/to/file


I recently found a service called gitzip and its also open source:

site - http://kinolien.github.io/gitzip/

repo - https://github.com/KinoLien/gitzip

Vist the above site, enter the repo or directory URL, you can download individual files or whole directory as a zip file.


According to this gist, you can use wget or cURL:

  1. Click the file name in a GitHub repo.
  2. Click Raw to display the file contents.
  3. Copy the URL in your browser.
  4. In the command line, run either:

    • wget --no-check-certificate --content-disposition https://URL-from-step3/
    • curl -LJO https://URL-from-step3/

    One more: in RHEL7.6, run the following:

    • wget https://URL-from-step3/ --output-document=FILE_NAME

In case you want to download a zip file from github using wget

wget -O filename.zip https://github.com/downloads/user/repository/filename.zip?raw=true

see this website for more details


I used the following format, and I feel it's important to inform about the path.

https://github.com/user/repository/raw/branch/filename

^^^the above is not very complete in my mind

https://github.com/<user>/<repoROOTname>/blob/master/<path>/<filename>?raw=true

some said raw.github.com or raw instead of blob, but the 2nd line works for me and I hope will help others...

2ยข


Now it's possible to download any file or any particular folder within the repository using this google chrome extention:

GitZip for github : link : https://chrome.google.com/webstore/detail/gitzip-for-github/ffabmkklhbepgcgfonabamgnfafbdlkn

Usage :

  1. In any GitHub public repos page.
  2. Just double click on the items you need.
  3. Click download button at bottom-right.
  4. See the progress dashboard and wait for browser trigger download.
  5. Get the ZIP file.

enter image description here

enter image description here


I think the new url structure is raw.giturl for example:

git file

raw


There is a chrome extension called Enhanced Github

It will add a download button directly to the right of each file.

enter image description here


This would definitely work. At least in Chrome. Right click on the "Raw" icon -> Save Link As.


  1. Copy page link simply
  2. In command line type: wget -L (exact copied link)
  3. Just replace blob to raw in step 2
  4. Enter

You can use the V3 API to get a raw file like this (you'll need an OAuth token):

curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/*owner*/*repo*/contents/*path*

All of this has to go on one line. The -O option saves the file in the current directory. You can use -o filename to specify a different filename.

To get the OAuth token follow the instructions here: https://help.github.com/articles/creating-an-access-token-for-command-line-use

I've written this up as a gist as well: https://gist.github.com/madrobby/9476733


  1. On the right hand side just below "Clone in Desktop" it say's "Download Zip file"
  2. Download Zip File
  3. Extract the file

Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to version-control

How can I switch to another branch in git? Do I commit the package-lock.json file created by npm 5? Project vs Repository in GitHub Remove a modified file from pull request Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository." Git: How to squash all commits on branch git: updates were rejected because the remote contains work that you do not have locally Sourcetree - undo unpushed commits Cannot checkout, file is unmerged Git diff between current branch and master but not including unmerged master commits

Examples related to github

Does the target directory for a git clone have to match the repo name? Issue in installing php7.2-mcrypt How can I switch to another branch in git? How to draw checkbox or tick mark in GitHub Markdown table? How to add a new project to Github using VS Code git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 How to add empty spaces into MD markdown readme on GitHub? key_load_public: invalid format git - remote add origin vs remote set-url origin Cloning specific branch