当我尝试使用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 remote set-url origin https://<token>@github.com/<username>/<repo>.git/

首先,您需要基于SSH密钥的身份验证

Windows教程:SSH密钥验证 Linux/Mac教程:SSH基于密钥的身份验证 文档

然后

生成个人令牌 设置你的用户名:git config——global user.name "userName" 设置您的电子邮件地址:git config—global user。电子邮件“电子邮件” Git配置——全局凭据。辅助缓存 Git push/ Git pull之类的用户名和密码(个人token)


你可以跟随这个视频:使用Git和GitHub的个人访问令牌

如果您想第一次克隆:

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

Android Studio Arctic Fox解决方案(Windows 10)

我在Android Studio Arctic Fox(最新版本)中使用个人访问令牌进行了身份验证,但我仍然在2021年8月14日得到了这个错误:

remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

我在github.com上生成了一个新的访问令牌,从Android Studio中删除了我的GitHub帐户,并再次使用新的访问令牌添加帐户。但是,它仍然显示出同样的错误。

我在Stack Overflow上阅读了其他解决方案,下载了GitHub CLI,并在Windows命令提示符中成功添加了我的GitHub帐户和访问令牌,并尝试从Android Studio再次推送存储库,同样失败。

然后,在本文之后,我在命令行中执行了以下操作:

cd <project-directory>
git remote set-url origin https://<TOKEN>@github.com/<user_name>/<repo_name>.git

我从Android Studio再次推送,它终于工作了!

我以前在Linux上使用git拉密码。

如果是这种情况,您唯一需要做的就是使用令牌来代替密码。

通过转到个人访问令牌生成一个访问令牌。

这里有一个git拉的例子

git pull

Username for 'https://github.com': gitusername
Password for 'https://yourusername@github.com': //Then enter generated token