22

I need the ability to download our application at specific tags, but I am unable to find a working solution for this. Downloading tarballs based on git tag seems promising but I am unable to get it working using Curl. I have tried the following but all I get back is the source for the github 404 page.

curl -sL https://github.com/$ACCOUNT/$PRIVATE_REPO/tarball/0.2.0.257m?login=$MY_USER_NAME&token=$MY_TOKEN > 0.2.0.257m.tar
SJP
  • 586
  • 1
  • 6
  • 13

3 Answers3

30

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
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 3
    Your second link helped me get things working. 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` – SJP Apr 09 '12 at 17:40
  • @Steven_JP Excellent. I have included your command in the answer for more visibility. – VonC Apr 09 '12 at 17:42
  • Not sure if those wget examples would still work, but this worked for me: http://stackoverflow.com/questions/23347134/downloading-a-tarball-from-github-without-curl – errordeveloper Apr 28 '14 at 17:37
18

After creating an access token,

you can use wget:

wget --output-document=<version>.tar.gz \
    https://api.github.com/repos/<owner>/<repo>/tarball/<version>?access_token=<OAUTH-TOKEN>

or curl:

curl -L https://api.github.com/repos/<owner>/<repo>/tarball/<version>?access_token=<OAUTH-TOKEN> \
    > <version>.tar.gz

More information can be found in GitHub's API reference for archive links.

tjanez
  • 2,175
  • 1
  • 21
  • 14
  • it might be that you need to add the '--no-check-certificate' argument: ```wget --no-check-certificate --output-document=.tar.gz https://api.github.com/repos///tarball/?access_token=``` – Vincent Claes Oct 08 '18 at 07:11
  • 2
    This was the one that got me closest. The only difference is that GitHub api now wants the token in the header of the request. Eg. ```curl -L -H "Authorization: token " https://api.github.com/repos///tarball/ > out.tar.gz``` – Kahitarich Dec 25 '21 at 00:32
  • 1
    As of 2020-02-10 this has been deprecated unfortunately :'( https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param/ . removed as of september 8th 2021 – Themis Jul 23 '22 at 20:21
1

Log into your Private Org on Github.com, then go here to create your token: https://github.com/settings/applications#personal-access-tokens

When trying to Curl into your Private Org, use the following:

curl --header 'Authorization: token ADDACCESSTOKENHERE' \
 --header 'Accept: application/vnd.github.v3.raw' \
 --remote-name \
 --location https://api.github.com/repos/ORG/PROJECT/contents/FILE

Replace what's in CAPS with your information...

Gamma
  • 27
  • 1
  • For some reason, I had issue with sending multiple headers with curl to Github API to download a binary asset, when one header is for auth. It returns XML response of "Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified". But if I changed the auth from being a header to query string parameter, then it works. So just mentioning this quirk. – David Sep 22 '15 at 19:12