如何从无法访问本地计算机上的“git”的 GitHub 下载私有存储库?

Kam*_*nek 9 download wget github curl headers

我想要做的是从 GitHub 下载私有存储库存档,解压缩它,删除存档文件并复制下载项目中的一些目录。

我尝试使用wget但我无法授权自己:

wget --header='Authorization: token MY_TOKEN_CREATED_ON_GITHUB' https://github.com/MY_USER/MY_REPO/archive/master.tar.gz -O - | tar xz
Run Code Online (Sandbox Code Playgroud)

我也试过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
Run Code Online (Sandbox Code Playgroud)

这里授权通过,但我无法提取文件。

怎么做?

tja*_*nez 5

解决方案wget类似于:

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>/
Run Code Online (Sandbox Code Playgroud)

笔记:

  • --strip-components=1 将删除包含在 GitHub 创建的存档中的顶级目录,
  • 确保不要/在要使用cp( <dir1>, <dir2>, ..., <dirn>)复制的目录末尾放置尾随,并且尾随/出现在目标目录 ( <destination-dir>)的末尾。