我已经使用GitHub有一段时间了,git添加、git提交和git推送都没问题,到目前为止还没有任何问题。突然我出现了一个错误

fatal:认证失败

在终端中,我克隆了一个存储库,处理了一个文件,然后我使用git add将文件添加到提交日志中,当我做git提交时,它工作得很好。最后,git push请求用户名和密码。我输入正确,每次我这样做,它都会显示相同的错误。

这个问题的原因是什么,我该如何解决它?

.git/config的内容如下:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = http://www.github.com/######/Random-Python-Tests
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[user]
        name = #####
        email = ############

当前回答

对我来说,我忘记了我已经在github.com上更改了密码,我的shell身份验证的钥匙链从未更新到新密码。

从我的钥匙链中删除所有Git,然后重新运行Git请求帮助解决了这个问题,再次提示我输入新密码。

其他回答

如果你在你的GitHub帐户中启用了双因素身份验证,你 将无法使用您的帐户密码通过HTTPS推送。而不是 您需要生成一个个人访问令牌。这可以在 GitHub帐户的应用程序设置。使用此令牌作为您的 密码应该允许您通过HTTPS推送到远程存储库。 像往常一样使用你的用户名。

创建个人访问令牌

如果存储库设置为HTTPS,您可能还需要更新存储库的起源。切换到SSH:

git remote -v
git remote set-url origin git@github.com:USERNAME/REPONAME.git

在Windows上,尝试以下步骤编辑或删除保存的凭据:

Click Start Type: Credential Manager (on Windows 10, this is under "Start → Settings". Then search for "Credential Manager") See the Windows Credentials Manager shortcut and double-click it to open the application. Once the application is open, click on the Windows Credentials tab. Locate the credentials that you want to remove/update. They will start with "git:" and might begin with "ada:" Click on the credential entry. It will open a details view of the entry. Click Edit or Remove as required and confirm. Later rinse and repeat as necessary.

我也有同样的问题。我这样设置URL:

git remote set-url origin https://github.com/zkirkland/Random-Python-Tests.git

我还从配置文件中删除了这个条目:askpass = /bin/echo。

然后“git push”问我的用户名和密码,这一次它成功了。

这个问题在GitHub引入双因素身份验证之前就已经提出了,然而,自从GitHub引入2FA以来,许多人都遇到了这个错误。

每次你尝试推送时,GitHub都会要求验证,如果你想避免重复提示,你应该使用GitHub -cli,它非常轻量级,你可以安装apt, yum, dnf和pacman。

安装github-cli后,

输入以下命令

gh auth login

选择要验证的帐户类型 选择HTTPS或SSH(根据需要) 使用web浏览器登录或根据您的轻松程度使用访问令牌进行身份验证。

访问令牌可以从GitHub > Settings > Developer-settings >生成访问令牌,复制令牌并粘贴到终端,这是一次性的代码,所以在终端上进行身份验证之前,请确保您不会丢失代码

我遇到过

git fetch

fatal: Authentication failed for 'http://...."

在我的Windows密码过期并被更改之后。使用Windows凭据管理器多次获取、重新启动甚至重新安装Git都没有帮助。

令人惊讶的是,正确答案在评论中,而不是在答案中(其中一些真的很奇怪!)

你需要进入控制面板→凭据管理器→Windows凭据并更新git的密码:http://your_repository_address