我已经使用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帐户上启用了双重身份验证,然后登录到你的GitHub帐户,然后转到

新的个人访问令牌

若要生成新的访问令牌,请复制该令牌,并将其作为密码粘贴到终端中进行身份验证。

其他回答

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

git push -u origin branch_name_that_you_want_to_push

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

我也有同样的问题。重新启动我的系统后,它工作了。

同样的错误(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拉现在提示用户名/密码提示。

我不确定我做了什么得到这个错误,但做:

git remote set-url origin https://...

对我没用。然而:

git remote set-url origin git@bitbucket.org:user/repo

以某种方式工作。

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