我已经使用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 remote set-url origin https://...

对我没用。然而:

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

以某种方式工作。

其他回答

我刚刚为我的Github帐户启用了双因素身份验证,所以我禁用了双因素身份验证,我可以用我的UID和PWD登录

如果你在你的GitHub帐户上启用了双重身份验证,然后登录到你的GitHub帐户,然后转到

新的个人访问令牌

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

我认为由于某种原因,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的问题。要解决此问题,在机器上安装Git时,取消选中“启用Git凭据管理器”选项。

我得到以下错误时,试图推动到github远程

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

解决方案 github账户上的SSH密钥丢失

从~/复制本地公共ssh密钥。ssh目录 粘贴到Github >设置> SSH和GPG密钥>新的SSH密钥 试试ssh -T git@github.com 这应该会输出 嗨xxxxx !您已成功验证,但GitHub不提供shell 访问。