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

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计划的一部分,很快将是永久的服务变化


当前回答

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

_____________________________ 生成个人访问令牌:

点击这里并生成一个个人访问令牌。这太简单了。 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

其他回答

之前接受的Kusal Shrestha的答案可以完成这项工作,但它并不安全,因为我们将令牌存储在纯文本中。

在我看来,将它存储在钥匙链中是更好的方法。

对于Visual Studio Code,请阅读crg的回答。

Windows:

你可以试试下面的@Venryx评论,但我还没有测试过。


Mac:

我现在才面对这个问题

按照建议,我按照这个URL进入开发设置并生成了一个令牌。

然后我进入我的Mac的钥匙链访问:

我删除了(所有)行的GitHub

现在我去终端输入了虚拟代码

git push

终端要求我输入我的邮箱和密码。

我输入了我的电子邮件,对于密码,我输入了我之前生成的令牌。

然后它又开始工作了。

这招对我很管用:

生成个人访问令牌(不要忘记复制令牌) 打开您的钥匙链访问(Mac)或凭据管理器(Windows)。 在KeyChain access /Credential Manager中使用新的个人访问令牌更新GitHub密码 最后一步:克隆Git(确保将存储库克隆到正确的目录位置) Git克隆https://github.com/username/repo.git 用户名:your_username 密码:your_token

在我的情况下,它没有提示我的用户名和密码,因为它已经在钥匙串访问更新。

从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

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

GitHub已禁用密码认证,且不再支持密码认证。创建并使用个人访问令牌(PAT)而不是密码。

以下步骤:

Remove GitHub stored credentials from the keychain. (For example, using "Keychain Access" on Mac, or "Credential Manager" on Windows) Generate access-token from GitHub Settings → Developer Settings → Personal access tokens → Generate new token Save the token - as it will be available there for once only Run command git fetch (or git push, if fetching doesn't require permissions) If on Windows, you must run this from PowerShell, not the command prompt (CMD). The command prompt consistently fails with the remote: Password authentication is temporarily disabled message, despite identical inputs. It will ask for your user name and password. If it does not ask you for your username and password, you must change your Git remote URL to contain your username: https://USERNAME@github.com/repo-owner/repo-name.git (see approach 2 for instructions on changing remote URL) Use the access token instead of the password when it asks for a password (you will have to enter it twice)

或者第二种方法:

从GitHub生成访问令牌: 设置→开发人员设置→个人访问令牌→生成新的令牌 在本地更新origin的URL: git remote set-url origin https://<token>@<git_url>.git 拉一次:git拉https://<token>@<git_url>.git