11

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?

3

2 Answers 2

7

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

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .