我已经使用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服务帐户(git)的登录名或密码,就会发生这种情况。你也需要在Windows凭证管理器中更改它。在Windows搜索菜单中输入“凭据管理器”打开它。

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

在Windows上,尝试以下步骤编辑或删除保存的凭据:

Click Start Type: Credential Manager (on Windows 10, this is under "Start → Settings". Then search for "Credential Manager") See the Windows Credentials Manager shortcut and double-click it to open the application. Once the application is open, click on the Windows Credentials tab. Locate the credentials that you want to remove/update. They will start with "git:" and might begin with "ada:" Click on the credential entry. It will open a details view of the entry. Click Edit or Remove as required and confirm. Later rinse and repeat as necessary.

我昨天开始在Ubuntu 20.04的Visual Studio Code中遇到这个问题。

我没有对我的GitHub凭证进行任何更改,也没有在项目中更改任何内容,但我运行任何git命令来与我的远程分支进行通信,例如:

git pull origin dev

我得到的错误如下:

remote:未找到存储库。 致命:“https://github.com/MyUsername/my-project.git/”认证失败

以下是对我有效的方法:

我尝试重新克隆项目,然后运行git pull命令,但它不起作用。

git clone https://my-git-url

我尝试使用以下命令再次设置我的凭据,但仍然没有运气:

git config --global user.email "email@example.com"
git config --global user.name "John King"

我尝试删除远程存储库,并使用以下命令重新添加它,但仍然没有运气:

git remote remove origin
git remote add origin https://my-git-url

最后,我决定尝试使用我默认的Ubuntu终端,它工作得很好。我最大的猜测是,这是Visual Studio Code在几个小时前的最后一次更新中的一个错误(请参阅截图,它显示发布是在我遇到这个问题的同一天完成的)。我的意思是我使用snap设置Visual Studio Code,所以它可能已经在后台更新了几个小时。

希望他们能解决这个问题,git远程操作将再次恢复正常。

首先,你可以确保使用正确的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以避免错误消息。

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

git push -u origin branch_name_that_you_want_to_push

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