Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 717
jayarjo Avatar asked Feb 29 '12 18:02

jayarjo


People also ask

Can a private GitHub repo be cloned?

Any GitHub user who has two-factor authentication enabled must use a personal access token to clone a private GitHub repository.

How do I access 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.

Can you search for private repository GitHub?

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."

Can private repositories be seen?

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.


2 Answers

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.

like image 186
roychri Avatar answered Sep 18 '22 13:09

roychri


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)

like image 20
link Avatar answered Sep 21 '22 13:09

link