GitHub获取私有仓库


使用 Token(个人访问令牌) 来克隆私有 GitHub 私有仓库!

GitHub获取私有仓库


自从 Github 开放私有仓库以来,有很多用户都会创建私有仓库,进行开发也罢,进行存储隐私也行。正巧,最近遇到这样一个问题,就是准备将一个私有仓库开源出来,但是因为 Github 自动的 Actions 不能够满足我的构建需求,所以我使用的是自己服务部署 CI 服务进行自动化构建的。

但是,我本地服务需要获取私有仓库的时候就出现了问题。一方面,本地部署的 CI 服务没有提供对应的插件来完成稀有仓库的拉去;另一方面,就是如果使用 token 令牌的话,我如果将其妥善的保存起来。对于第二点,我这里就不过多赘述了,主要自己的实际情况关联比较近。

  1. 获取 token 令牌
  2. 给予 token 令牌如下权限并报错对应值
repo:status
repo_deployment
public_repo
repo:invite
security_events
  1. 命令行使用方式
$ git clone https://${TOKEN}:[email protected]/username/repo.git

有了令牌后,在通过 HTTPS 执行 Git 操作时,可以输入令牌而不是密码。个人访问令牌只能用于 HTTPS Git 操作。如果存储库使用 SSH 远程 URL,则需要将远程 URLSSH 切换到 HTTPS

$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token

以下是在 Github 中,获得自己的 token 令牌的操作步骤。—— 搬自(Creating a personal access token)

  • In the upper-right corner of any page, click your profile photo, then click Settings.

GitHub获取私有仓库

  • In the left sidebar, click Developer settings.

GitHub获取私有仓库

  • In the left sidebar, click Personal access tokens.

GitHub获取私有仓库

  • Click Generate new token.

GitHub获取私有仓库

  • Select the scopes, or permissions, you’d like to grant this token. To use your token to access repositories from the command line, select repo.

GitHub获取私有仓库

  • Click Generate token.

GitHub获取私有仓库

  • Click to copy the token to your clipboard. For security reasons, after you navigate off the page, you will not be able to see the token again.

GitHub获取私有仓库


文章作者: Escape
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Escape !