How to Download a Tarball from Github Using Curl

How do I download a tarball from GitHub using cURL?

Use the -L option to follow redirects:

curl -L https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx

Download github release with curl

If you do the following it will download correctly:

wget https://github.com/yarnpkg/yarn/releases/download/v0.23.4/yarn-v0.23.4.tar.gz

If you want to use curl you have to use the redirect -L option to follow redirect link and direct the output in a file like this:

curl -L https://github.com/yarnpkg/yarn/releases/download/v0.23.4/ya‌​rn-v0.23.4.tar.gz > yarn.tar.gz

Downloading a tarball from github without curl

After beating my head on various combination of wget flags involving either:

  • --post-data; or
  • --user= with and without --pasword= as well as vice versa; or
  • --header="Authorization: token <token>"

I looked back at the documentation and found that there are alternative endpoints in releases API. Looks like firstly I just cannot use the Authorization header with the server that hosts tarballs and secondly curl (or github front-end, based on the agent string) seem to be doing a different thing with <token>@github.com vs wget's --user=<token>, and it's not the most pleasant thing to figure out.

So what works is this:

wget \
--header='Authorization: token <token>' \
https://api.github.com/repos/<org|user>/<repo>/tarball/<ref>

Having trouble downloading Git archive tarballs from Private Repo

For public repo, you have this gist listing some examples:

wget --no-check-certificate https://github.com/sebastianbergmann/phpunit/tarball/3.5.5 -O ~/tmp/cake_phpunit/phpunit.tgz

For a private repo, try passing your credential information in a post directive:

wget --quiet --post-data="login=${login}&token=${token}" --no-check-certificate https://github.com/$ACCOUNT/$PRIVATE_REPO/tarball/0.2.0.257m

Or use a curl command as in SO question "git equivalent to svn export or github workaround", also explained in great details in:

"A curl tutorial using GitHub's API".


The OP Steven Jp reports having made the curl command work:

The final curl command ended up looking something like this:

curl -sL --user "${username}:${password}" https://github.com/$account/$repo/tarball/$tag_name > tarball.tar

(in multiple lines for readability)

curl -sL --user "${username}:${password}" 
https://github.com/$account/$repo/tarball/$tag_name
> tarball.tar

can't download github project with curl command


curl -L -O https://github.com/ziyaddin/xampp/archive/master.zip
  • you must use https://
  • you must use -L to follow redirects

How to download the Release tar file from Github?

Add -L flag to the curl command in order to follow redirects.

example:

curl -O -L https://github.com/gulpjs/gulp/archive/v3.9.1.tar.gz

How do I download release artifacts from a GitHub enterprise repository using wget/curl?

From the documentation, you must hit:

/repos/{owner}/{repo}/tarball/{ref}

First of all, create a GitHub token with the necessary read permissions.

Then, if we say that:

  • {owner} is paolo
  • {repo} is mycoolrepo
  • {ref} is 1.0.0

then you can use:

$ curl -s -L -H "Authorization: token INSERT_TOKEN_HERE" https://github.MY_ENTERPRISE_NAME.com/api/v3/repos/paolo/mycoolrepo/tarball/1.0.0 --output release_zip

obviously, replace INSERT_TOKEN_HERE and MY_ENTERPRISE_NAME with the token and the organisation name respectively.

You can confirm the download has been successful with file; for a successful download, it should look as follows:

$ file release_zip
release_zip: gzip compressed data, from Unix, original size 51200

GitHub Api download zip or tarball link

You can wget your way out of the GitHub repo to get a tar file (archive):

wget --no-check-certificate https://github.com/User/repo/archive/master.tar.gz

# better, if the certificate authorities are present:
wget https://github.com/User/repo/archive/master.tar.gz

will get you a file named 'master' from the user 'User''s repo 'repo'.

The updated V3 API url is:

https://api.github.com/repos/User/repo/:archive_format/:ref
#
# two possibilities for fomat:
https://api.github.com/repos/User/repo/tarball/master
https://api.github.com/repos/User/repo/zipball/master

# from github example:
$curl -L https://api.github.com/repos/octokit/octokit.rb/tarball > octokit.tar.gz

You can then tar xpvf master, getting the full archive. It will create a directory following the naming convention described in the question you mentioned.

No Git binary is needed to get an archive from GitHub, thanks to their download service "Nodeload".


ligemer proposed in an edit the following example:

Edit 2016-08-25 - Shell Example With Wget, Variables, and Untar:

#!/bin/bash -ex

# arguments:
# token = $1
# organization = $2
# repo name = $3
# branch = $4

wget --header="Authorization: token ${1}" --header="Accept:application/vnd.github.v3.raw" -O - https://api.github.com/repos/${2}/${3}/tarball/${4} | tar xz

Call via:

$ scriptName.sh token my-organization site.example master

The command above will download and extract the GitHub folder to the same directory as the script.


Diogo Quintela suggests in the comments:

The following example allow the download, extract and cut the top level directory

curl -L https://api.github.com/repos/octokit/octokit.rb/tarball | tar xz --strip=1


Related Topics



Leave a reply



Submit