我已经使用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请求帮助解决了这个问题,再次提示我输入新密码。

其他回答

我遇到过

git fetch

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

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

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

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

如果您更改了git服务帐户(git)的登录名或密码,就会发生这种情况。你也需要在Windows凭证管理器中更改它。在Windows搜索菜单中输入“凭据管理器”打开它。

Windows凭证管理器->Windows凭证和在通用凭证下编辑您的git密码。

同样的错误(Windows, Git Bash命令行)。使用https应该提示登录凭证,但错误:

$ git pull origin master
fatal: Authentication failed for 'https://github.com/frmbelz/my_git_project.git'
$ git config -l
...
credential.helper=manager
...

$ git config --global --unset credential.helper
$ git config --system --unset credential.helper

Git拉现在提示用户名/密码提示。

我认为由于某种原因,GitHub期望URL没有子域www。当我使用(例如)

git remote set-url origin https://www.github.com/name/repo.git

它给出了以下信息:

remote: Anonymous access to name/repo.git denied
fatal: Authentication failed for https://www.github.com/name/repo.git

然而,如果我使用

git remote set-url origin https://github.com/name/repo.git

它工作得非常好。这对我来说没什么意义…但我想记得不要把www放在GitHub存储库的远程URL中。

另外请注意,GitHub存储库网页上提供的克隆url不包括www。

我在Windows上也遇到了同样的问题。大多数时候,由于使用多个Git帐户,我通常会遇到这个问题。如果您使用的是Windows操作系统,请以管理员身份打开终端并尝试再次运行这些命令。请确保您具有管理员权限。