Programatically download private repository using Curl


I am going nuts figuring this out , going through tons of google/stackflow/blogs pages but have not found clear answer.

I would like to programatically download repository in ZIP format using Curl and my personal github token.


$token -> my personal token

$org -> my organization as a owner of repositories

$repo -> private repository I would like to download

I am trying to use something like this:

curl -H “Authorization: $token” -L$org/$repo/zipball >

but it produces following json:


  “message”: “Not Found”,

  “documentation_url”: “


Please help !!

Hey @dq-shripad,

Thanks for being here! AFAIK the supported and reliable way of downloading an archive file of repository contents programmatically is to correctly authenticate with the API and use the Get archive link API endpoint.

I hope this helps!

1 Like

finally figured out the issue.

The problem was not in curl option/syntax used on command-line.

The problem was in personal access token I had created. I was using an access token created with basic and repo permissions. Aparently, this was not enough.

I then created another access token will full permissions (every permission setting offered ) and with this token I was able to extract repo zip file. 

two things I would like to point out :

  1. The first token created should have worked…not sure why it didn’t. I should not have to create a token will all permissions.

  2. When I used first token, Github API reported that “repositary not fund” even though it existed.!  The message should have been "access token does not have required permissions " or simply "bad credentials ".

Hope Github API team can review this and make changes to their messaging.


Thanks AndreaGriffiths11.

I think the issue was not with authentication but authorization. I have shared my findings.


I am also facing a similar kind of issue.

Can you please send me the exact query that you were using.

In my case i need to access the latest release tag name 

and download the zip file.

curl -H “Authorization: token tokenid”

curl -u username:token

the above two did not work.

You’re missing a "-L " prior to the repo, for instance
Also I don’t know if “releases/latest” work
For me I did “/me/repo/tar.gz/master”

curl -H “Authorization: token $GITHUB_MASTER” -L > repo.tar.gz

This helped me. Thanks!

download_release() {
    curl -vLJO https://$$REPO/zipball/master
1 Like

Hey! It seems you can only download a release and it’s subsequent zip file, but this part of the API will allow you to do this:

…and for those like me who got here looking for a one-liner command line to clone private repos on other servers, the command is simply:

git clone https:// **yourtoken***user*/*repo*.git

A token can be generated here: