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

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


当前回答

你所要做的就是使用一个生成的令牌而不是传统的密码:

使用密码的旧方法:

git clone https://github.com/username/repo.git

Username: your_username
Password: your_password

使用令牌的新方法:

git clone https://github.com/username/repo.git

Username: your_username
Password: your_token

步骤1:从GitHub生成API令牌

阅读本文档创建个人访问令牌:配置双因素身份验证

步骤2:用新生成的令牌替换之前缓存的密码

正如这里回答的,你必须修改你的本地GitHub登录凭证缓存在你的电脑: 从Git中删除凭证

其他回答

如果你使用的是HTTPS版本而不是SSH版本,那么这个错误将会出现,因为GitHub正在删除HTTPS方法来维护存储库。

生成一个SSH密钥,如果你还没有SSH -keygen,并继续按Enter直到结束 猫~ / . ssh / id_rsa。Pub -复制结果 访问https://github.com/settings/keys 单击“新建SSH密钥”,将密钥粘贴到文本框中。标题可以是任何你想要的 CD <到项目的目录> Git remote set-url origin git@github.com:<username-here>/<repository-name-here>.git

你可以开始了!

首先从帖子: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→设置→开发者设置→个人访问令牌。重新生成令牌并复制它。 在任何本地存储库上,当git推送时,输入您的用户名,密码是生成的令牌

无需为每个HTTPS Git操作手动输入令牌,您可以使用Git客户端缓存令牌。

在终端中输入如下命令:

# Set Git to use the credential memory cache
git config --global credential.helper cache

输入如下命令修改默认密码缓存超时时间。

# Set the cache to timeout after 1 hour (setting is in seconds)
git config --global credential.helper 'cache --timeout=3600'

创建个人访问令牌 在Visual Studio Code命令行中: Git配置——全局凭据。辅助(YOUR_TOKEN)

你所要做的就是使用一个生成的令牌而不是传统的密码:

使用密码的旧方法:

git clone https://github.com/username/repo.git

Username: your_username
Password: your_password

使用令牌的新方法:

git clone https://github.com/username/repo.git

Username: your_username
Password: your_token

步骤1:从GitHub生成API令牌

阅读本文档创建个人访问令牌:配置双因素身份验证

步骤2:用新生成的令牌替换之前缓存的密码

正如这里回答的,你必须修改你的本地GitHub登录凭证缓存在你的电脑: 从Git中删除凭证