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

当前回答

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

其他回答

在Windows系统上,这个功能对我很有效,它还能记住我的证书:

运行Git Bash 指向存储库目录 执行git config——global credential命令。辅助wincred

快速的GUI方法是:

首先通过create app access token生成一个访问令牌。 然后进入sourceTree的设置(放在Source树的关闭按钮下) 将出现一个名为“Repository Settings”的提示。 使用https://USER_NAME:ACCESS_TOKEN@bitbucket.org/REPO_NAME/PROJECT_NAME.git添加/编辑您的存储库路径

或为github帐户

https://username:access-token@github.com/username/repo.git

这里要提到的唯一变化是将上述共享创建应用程序访问令牌链接生成的附加accessToken添加到现有路径url中。

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

我得到以下错误时,试图推动到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 访问。

首先,你可以确保使用正确的URL:

git remote set-url origin https://github.com/zkirkland/Random-Python-Tests.git

然后,如果它之前工作,如果它没有要求您的用户名,这一定是因为您已经将您的凭据(登录名/密码)存储在$HOME/.netrc文件中,正如这里所解释的那样。您可以再次检查这些设置,并确保您的代理(如果有的话)没有更改。

检查git配置——global credential.helper的输出。 并确保凭证是你的GitHub用户帐户,和一个PAT(个人访问令牌)。

您可以使用Git凭据助手更新您的凭据,如下所示。


如果这仍然不工作,你可以切换到SSH URL:

git remote set-url origin git@github.com:zkirkland/Random-Python-Tests.git

但这意味着您已经在帐户设置中发布了SSH公钥。


有关Visual Studio Code的具体信息,请参见“git push:缺少或无效凭证”。致命:'https://github.com/username/repo.git'认证失败"

您可以取消选择设置git。terminalAuthentication以避免错误消息。