当我尝试使用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日周二到期。为什么今天这个被删除了?


当前回答

从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)

其他回答

生成一个GitHub个人访问令牌(PAT)

登录你的GitHub账户,打开设置→开发者设置 个人访问令牌。 单击Generate New Token。

不要忘记复制和代币后生成。它只能访问一次。

窗户

打开控制面板→用户帐户→凭证管理器。 现在,查找git:https://github.com。 点击编辑。 将密码替换为GitHub个人访问令牌。

MAC

点击聚光灯图标,搜索钥匙链访问。 在钥匙串访问,搜索github.com。 现在,寻找github.com的互联网密码条目。 更新条目。

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再次推送,它终于工作了!

在获得令牌密钥后,您可以跳过所有步骤并执行以下操作:

git clone https://your_username:your_github_token@github.com/username/private-repo.git

到目前为止,我找到的最佳解决方案是:

安装GitHub CLI, brew Install gh或查看其他操作系统如何安装 在终端中输入gh auth login 这样做: 您想登录哪个账户? 选择GitHub.com Git操作的首选协议是什么? 选择HTTPS 用你的GitHub凭证验证Git ? 选择是的 您想如何验证GitHub CLI? 选择“使用web浏览器登录” (复制一次性代码粘贴到浏览器) 按“Enter”在浏览器中打开github.com

对于Ubuntu,请执行以下步骤

在https://github.com/settings/tokens上,生成一个令牌。 git推 用户名:user_github_username 密码:add_generated_token代替密码。