Downloading a Tarball from Github Without 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

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>

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

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

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

Changing name of top-level directory when downloading a tarball from GitHub?

Use the newer .../archive/... link rather than the .../tarball/... link in your question. The general format is:

https://github.com/<group_or_organization>/<repo>/archive/<refspec>.tar.gz

So, for example:

$ curl -L jttps://github.com/nativescript/docs/archive/production.tar.gz | tar tz
docs-production/
docs-production/.gitattributes
docs-production/.gitignore
docs-production/.gitmodules
docs-production/.vscode/
docs-production/.vscode/settings.json
docs-production/README.md
...

You can see that the generated top-level directory name uses whatever <refspec> you provided, rather than converting it into a commit id.

Similarly:

$ curl -s -L https://github.com/nativescript/docs/archive/ErikEdits-css-annimations.tar.gz   | tar tz
docs-ErikEdits-css-annimations/
docs-ErikEdits-css-annimations/.gitattributes
docs-ErikEdits-css-annimations/.gitignore
...

In place of a branch name you can use other git refspecs. For example:

https://github.com/nativescript/docs/archive/HEAD^.tar.gz

Or:

https://github.com/nativescript/docs/archive/v2.3.0-20-ged0d16f.tar.gz

But in these cases, the reference will be converted into a commit id.

Is there a link to GitHub for downloading a file in the latest release of a repository?

A few years late, but I just implemented a simple redirect to support https://github.com/USER/PROJECT/releases/latest/download/package.zip. That should redirected to the latest tagged package.zip release asset. Hope it's handy!

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


Related Topics



Leave a reply



Submit