We got a necessity to fetch a zipball of a private repo. For public ones it's pretty easy either through GitHub API or manually (https://github.com/user/repo/zipball/master). But what about private repos? Not exactly obvious how to do it even having oAuth token.
Any GitHub user who has two-factor authentication enabled must use a personal access token to clone a private GitHub repository.
Set up a GitHub SSH key. Add the public SSH key to a private repository's deploy keys. Store the private SSH key in Secret Manager. Submit a build that accesses the key from Secret Manager and uses it to access the private repository.
You can search for designated private repositories on GitHub Enterprise Cloud from your GitHub Enterprise Server instance. For more information about searching across environments, see "About searching on GitHub."
Public repositories are accessible to everyone on the internet. Private repositories are only accessible to you, people you explicitly share access with, and, for organization repositories, certain organization members.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With