当我尝试使用git pull时,我在控制台上得到了这个错误:

remote:在2021年8月13日删除了对密码认证的支持。请改用个人访问令牌。 remote:请参阅https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/了解更多信息。 致命:无法访问“…”:请求的URL返回错误:403

这很奇怪,因为我只是在两周前按照文档在GitHub上创建了一个令牌。该代币将于2021年10月26日周二到期。为什么今天这个被删除了?


当前回答

如果您想第一次克隆:

git clone https://<repository_owner>:<personal_access_token>@github.com/<repository_owner>/<repo>.git

其他回答

三个命令:

首先按照官方文档中的说明创建一个令牌:创建个人访问令牌

然后重置Git凭证

git config --global --unset credential.helper

克隆或拉出你的存储库:

`git pull` or `git clone`

然后输入令牌作为密码。

如果你想保存你的令牌,你可以使用:

git config --global credential.helper cache

对于想要使用Sourcetree的人:

在源路径上像这样复制:

https://<token>@github.com/<username>/<repo>

对于Mac

如果你在“GitHub”的钥匙链上没有任何东西,创建一个新的钥匙链项目并添加你的详细信息。从GitHub插入令牌来代替密码。

最简单的解决方案(2022年5月):

在“个人访问令牌”中创建一个新令牌 复制令牌(Windows: Ctrl + C, macOS: Cmd + C,或单击复制图标) 尝试推送本地存储库:git push 输入您的GitHub用户名 将令牌粘贴为密码

从GitHub获取一个访问令牌:

GitHub→设置→开发者设置→个人访问令牌→生成一个新的令牌

复制粘贴新的令牌到记事本。

打开Git Bash,输入以下命令:

git config --global credential.helper osxkeychain

git clone https://github.com/abc/angularProject.git

Username for 'https://github.com': Test

Password for 'https://test@github.com': (enter your token here)