如何使用个人访问令牌克隆、拉取和推送回购

  • 本文关键字:何使用 访问令牌 git github
  • 更新时间 :
  • 英文 :


今天GitHub为我提供了一种推送、克隆或拉取回购的新方法

当我试图推送我的项目时,我收到了以下错误消息:

remote: Password authentication is temporarily disabled as part of a brownout. Please use a personal access token instead.
remote: Please see https://github.blog/2020-07-30-token-authentication-requirements-for-api-and-git-operations/ for more information.
fatal: unable to access 'https://github.com/barimehdi77/Philosophers.git/': The requested URL returned error: 403

经过多次搜索,我发现GitHub添加了一个名为Personal access tokens的新安全更新,但谁能使用它?

您必须使用SSH密钥。为每台计算机创建一个,并将它们全部注册到您需要访问的repo中。这样可以逐个删除访问计算机。

一旦在Github中配置了SSH密钥,就可以阅读本文来设置个人访问令牌。

https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token

更新它告诉您如何更改文档中的令牌

在命令行上使用令牌

一旦您有了令牌,您就可以在通过HTTPS执行Git操作。

例如,在命令行中,您将输入以下内容:

$ git clone https://github.com/username/repo.git <--- HTTPS, not SSH
Username: your_username
Password: your_token <-------- THE TOKEN, not your password

个人访问令牌只能用于HTTPS Git操作。如果您的存储库使用SSH远程URL,您需要切换从SSH远程到HTTPS。

如果没有提示您输入用户名和密码,您的凭据可能会缓存在您的计算机上。您可以更新密钥链中的凭据,以将旧密码替换为代币

不是为每个HTTPS Git操作手动输入PAT,您可以使用Git客户端缓存您的PAT。Git将临时存储您的凭据在内存中,直到过期为止。你还可以将令牌存储在Git之前可以读取的纯文本文件中每个请求。有关更多信息,请参阅";缓存您的GitHubGit中的凭据">

还发现了一个很好的视频演练,可能有助于澄清一些问题。

https://www.youtube.com/watch?v=kHkQnuYzwoo

以前的密码将不起作用。您必须使用令牌作为密码。

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

您可以按照以下步骤创建您的代币:

https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token

最新更新