我已经使用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 = ############

当前回答

也许您最近更改了Git帐户的密码。 你可以使用-u选项来尝试git的push line:

git push -u origin branch_name_that_you_want_to_push

执行上述命令后,它将要求输入密码。提供更新后的密码。

其他回答

在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.

在从Gitlab登录之前强制执行“双因素认证”后,我们就遇到了这种情况。我们必须将文本粘贴到id_rsa中。pub到Gitlab,然后使用终端在VS代码中重新引入存储库。

给定的解决方案:使用个人访问令牌是绕过此问题的一种方法。我没有启用双重身份验证,但每当我登录到一台新PC时,我都会收到电子邮件验证码来验证PC。

解决方案: 你可以在浏览器上登录到GitHub并验证你的身份,这将让GitHub知道信任这台PC。然后,使用bash登录,这一次您的登录应该像往常一样工作,因为现在您被列入了白名单。


注意:如果你有任何现有的GitHub帐户,想要切换,那么,在凭证管理器> Windows凭证(通用凭证部分)中删除它。这样做将允许您在进行另一个git操作时登录。

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

创建个人访问令牌

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

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

我添加到Bitbucket与Git链接,必须删除存储的密钥,因为这导致了致命的错误。

为了解决这个问题,我打开命令提示符并运行

 rundll32.exe keymgr.dll, KRShowKeyMgr

我删除了负责登录的密钥,下次我将文件推到repo时,系统会提示我输入凭据,并输入正确的凭据,结果成功推入。