我使用用户名密码来推送我的代码。它工作了几个月,但突然我不能这样做,并得到这个错误:

Username for 'https://github.com': shreyas-jadhav
Password for 'https://shreyas-jadhav@github.com':
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.

请注意,这个链接没有任何帮助。即使使用生成的令牌也无济于事。

主持人注:这是GitHub计划的一部分,很快将是永久的服务变化


当前回答

首先从帖子:API和Git操作的令牌认证要求,它说

2021年年中-所有经过身份验证的Git操作都需要个人访问或OAuth令牌。

所以你需要使用个人访问令牌(PAT)来推送:

1获取您的个人访问令牌

在这里登录以访问存储库并添加一个新的个人访问令牌:个人访问令牌。生成一个并保持令牌的安全(离开后无法显示它)。

(在Android Studio中,您需要获得“repo”,“gist”和“read:org”的许可)

2使用个人访问令牌进行推送

在你得到令牌后,你可以用如下命令进行推送:

git push https://[personal access token]@github.com/[user name]/[repository Name].git

其他回答

从GitHub的开发者设置中生成一个新的令牌 更新远程URL: git remote set-url origin https://<token>@github.com/<Git_URL> 拉: git拉https://<token>@<Git_URL>.git

这样就可以开始了。

适用于macOS, Windows和Linux

解决方案1

删除现有的存储库(如果当前有任何更改,请对其进行备份): Mv my-repo my-repo.backup 创建SSH密钥并将其添加到GitHub(参见GitHub文档) 为SSH克隆存储库:git克隆git@github.com:group/repo-name.git

方案二(推荐方案)

Git远程删除原点 您必须添加一个访问令牌(请参阅GitHub文档以生成令牌) Git远程添加origin https://<token>@<git_url>.git Git拉https://<token>@<git_url>.git

使用Visual Studio代码

删除你的GitHub访问:

git credential-osxkeychain erase
⏎  host=github.com
⏎  protocol=https

不是推就是拉 它将提示您一个模态对话框。单击“允许”并按照流程操作。

我试了所有的方法,最后都奏效了。由于这个错误,我无法在我的存储库中推送,所以请至少尝试一次!

_____________________________ 生成个人访问令牌:

点击这里并生成一个个人访问令牌。这太简单了。 https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token 现在只需在PAT的帮助下按一下,而不是密码和用户名___________________ 要将更改推送到存储库: git push https://[个人访问令牌]@github.com/[用户名]/[存储库名称].git

您可以通过GitHub仪表板生成您的PAT(个人访问令牌)。

Step 1: Log in to your GitHub account. Step 2: In the upper-right corner of any page, click your profile photo, then click Settings. Step 3: In the left sidebar, click Developer settings. Step 4: In the left sidebar, click Personal access tokens. Step 5: Click Generate new token. Step 6: Give your token a descriptive name. Step 7: 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. Step 8: Click Generate token.

复制您的令牌到一个安全的位置,因为一旦您离开该页面,您将无法检索它,除非您创建一个新的。

还有一个非常简洁的脚本,有助于将HTTPS克隆的Git存储库转换为ssh协议,而无需删除和克隆Git存储库:

将HTTPS GitHub克隆转换为使用SSH