Git 推送导致“身份验证失败" [英] Git push results in "Authentication Failed"



我已经使用 Github 一段时间了,到目前为止我对 git addgit commitgit push 都很好没有问题.突然,我遇到了一个错误:

I have been using Github for a little while and I have been fine with git add, git commit, and git push so far with no problems. Suddenly I am having an error that says:


在终端中,我克隆了一个存储库,处理了一个文件,然后我使用 git add 将文件添加到提交日志中,当我执行 git commit 时,它工作正常.最后,git push 要求输入用户名和密码.我把它们正确地放进去,每次我这样做时,它都会说同样的错误.

In the terminal I cloned a repository, worked on a file and then I used git add to add the file to the commit log and when I did git commit, it worked fine. Finally, git push asks for username and password. I put those in correctly and every time I do this, it says the same error.


Does anyone have any idea what the cause of this problem is and how I can fix it?

.git/config 的内容是:

        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url =
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
        name = #####
        email = ############


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

If you enabled two-factor authentication in your Github account you won't be able to push via HTTPS using your accounts password. Instead you need to generate a personal access token. This can be done in the application settings of your Github account. Using this token as your password should allow you to push to your remote repository via HTTPS. Use your username as usual.

如果设置为 https,您可能还需要更新存储库的源:

You may also need to update the origin for your repository if set to https:

git remote -v 
git remote remove origin 
git remote add origin  
登录 关闭
发送“验证码”获取 | 15天全站免登陆