How can I download a private repository from GitHub having no access to ‘git’ on my local machine?

9

2

What I want to do is to download private repository archive from GitHub, extract it, remove archive file and copy some directories that are inside downloaded project.

I tried to use wget but I cannot authorize myself:

wget --header='Authorization: token MY_TOKEN_CREATED_ON_GITHUB' https://github.com/MY_USER/MY_REPO/archive/master.tar.gz -O - | tar xz

I also tried with cURL:

curl -i -H 'Authorization: token MY_TOKEN_CREATED_ON_GITHUB' https://github.com/MY_USER/MY_REPO/archive/master.tar.gz > file.tar.gz | tar xz

Here authorization passes, but I can't extract the file.

How to do that?

Kamil Lelonek

Posted 2014-03-30T13:10:16.200

Reputation: 203

Why don't you just use git clone https://github.com/MY_USER/MY_REPO? – Tero Kilkanen – 2014-03-30T20:35:58.117

1Because I'm doing it at server where there's no git. – Kamil Lelonek – 2014-03-30T21:17:52.837

Might solve your problem: http://stackoverflow.com/questions/23347134/downloading-a-tarball-from-github-without-curl

– errordeveloper – 2014-04-28T17:35:57.457

Answers

4

The solution with wget would be something like:

wget --header="Authorization: token <OAUTH-TOKEN>" -O - \
    https://api.github.com/repos/<owner>/<repo>/tarball/<version> | \
    tar xz --strip-components=1 && \
    cp -r <dir1> <dir2> ... <dirn> <destination-dir>/

Notes:

  • --strip-components=1 will remove the top-level directory that is contained in the GitHub created arhive,
  • make sure you don't put a trailing / at the end of directories that are to be copied with cp (<dir1>, <dir2>, ..., <dirn>) and that the trailing / is present at the end of destination directory (<destination-dir>).

tjanez

Posted 2014-03-30T13:10:16.200

Reputation: 143

0

Provided you have your own "Personal Access Token", you can download an archive of your repository's branch by using the curl command:

curl -k --header "PRIVATE-TOKEN: xxxx" https://gitlab.xxxxx/api/v4/projects/<projectID>/repository/archive?sha=630bc911c1c20283d3980dcb95fd5cb75479bb9c -o myFilename.tar.gz

ProjectID is displayed on the repo's main page.

You can obtain the SHA value from the webUI after selecting the branch you want from the pull-down and copying the value on the right for the SHA. See screenshot below:

enter image description here

The other way to do this is via wget like this:

wget --no-check-certificate -O myFilename.zip --header=PRIVATE-TOKEN:xxxx "https://gitlab.xxxx/api/v4/projects/<projectID>/repository/archive.zip?sha=630bc911c1c20283d3980dcb95fd5cb75479bb9c"

I hope that helps.

frakman1

Posted 2014-03-30T13:10:16.200

Reputation: 131