Is there anyway to programmatically fetch a zipball of private github repo?

New Alternative

Because the given accepted answer does not work anymore, I thought I would explain how I was able to do it with the new changes in the github API.

The new Download Api Link

First, I found information about downloading the archive here: https://developer.github.com/v3/repos/contents/#get-archive-link

Public Repo

If it's a public repo then it is very easy... you can do:

curl -L https://api.github.com/repos/pengwynn/octokit/tarball > octokit.tar.gz

Private Repo

If it's it is a private repo, you need to create an oAuth token by going to your settings and then selecting "Developer settings" / "Personal access tokens". I created a personal token.

Then using the instructions on the following page I found out how to get private repo that you have permission to: https://developer.github.com/v3/#authentication

Full Code

curl -H "Authorization: token ab499f3b..." \
-L https://api.github.com/repos/godzilla/my_priv_repo/tarball > wut.tar.gz

Be sure to replace ab499f3b... with your actual token.


I came across the same problem and this worked for me (as of Feb 2015):

curl -O -J -L -u $YOUROAUTHKEY:x-oauth-basic https://github.com/$USER/$REPO/archive/master.zip

The oAuth as a header solutions didn't work for me but what worked was stuffing the key into the username and specifying type. It then gave a 302 to redirect with the proper link.

Verbose command really helped me troubleshoot whether the credentials I was using were being accepted or not (404 vs 401)