How can I download a private repository from GitHub having no access to ‘git’ on my local machine?
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?
Solution 1:
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 withcp
(<dir1>
,<dir2>
, ...,<dirn>
) and that the trailing/
is present at the end of destination directory (<destination-dir>
).