无法 git push,致命:身份验证失败,用户名更改后

Posted

技术标签:

【中文标题】无法 git push,致命:身份验证失败,用户名更改后【英文标题】:Unable to git push, fatal: authentication failed, after username change 【发布时间】:2022-01-21 12:29:13 【问题描述】:

我发布 GitHub 代码更新的方式是在一个单独的文件夹中工作,然后将该文件夹复制粘贴到我可以提交和推送的 GitHub 文件夹中。我在 git CL 中工作(GitHub Desktop 不知何故让我失去了一些工作,所以我卸载了它)。问题是我最近更改了用户名。现在,当我尝试推动它失败时。未跟踪的更改也有问题,但我想我解决了这个问题。它不断在错误消息中向我显示旧用户名,并提示我不明白/认为不相关:

 ! [rejected]        gh-pages -> gh-pages (non-fast-forward)
error: failed to push some refs to 'https://github.com/old_username/old_username.github.io.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我试过git config --global user.name new_username

当我遇到同样的问题时,我将 git remote 更改为上周的那个。那个时候我最终推得很好。

当我尝试 /git-credential-manager-core.exe unconfigure 撤消过去的身份验证并重试时,即使尝试使用我的新 PAT 和用户名进行身份验证,git push 也会失败。

【问题讨论】:

***.com/questions/22844806/…你可以通过这个链接解决你的问题 谢谢,但我通过重新安装GitHub Desktop和git并重复步骤解决了它。也许有一个 GitHub 错误或者可能需要清除一些缓存...... “重新安装 GitHub Desktop 修复了它”意味着这是 GitHub Desktop 问题,不是 Git 问题,也不是 GitHub 问题。不过,很奇怪你会从命令行看到它。 “重新安装 Git 修复它”意味着在某处缓存了一个条目,并且从命令行查看它是有意义的。对于将来遇到这种情况的任何人,如果您能确定是哪一种情况,那将对他们有所帮助。 GH Desktop 和 git 都处理相同的工作流程,我对两者都有身份验证问题。缓存的条目将是我在凭证管理器中的 git 凭证,我不知道在哪里可以找到它,即使我可以显示它。没关系,他们现在走了。我已经尽我所能地问了我的问题,因为我也在处理不完整的信息。我不是专家,所以我无法确定到底是什么问题。我只能说可靠的“断断续续”奏效了。 【参考方案1】:

用户名更改后,您需要使用远程存储库的新 URL 更改远程。

git remote set-url origin https://github.com/new_username/repo_name.git

编辑: 但是,正如错误所暗示的那样,问题不在于用户名更改。它说得很清楚:

当前分支的尖端位于其远程分支的后面

如果您需要远程更改,您可以使用它;

git pull <remote-name> <branch-name>
# resolve any conflicts and then push
git push <remote-name> <branch-name>

您也可以忽略远程更改并使用-f 选项强制推送本地更改;

git push -f <remote-name> <branch-name>

【讨论】:

谢谢 - 我做到了,身份验证仍然失败 - 有和没有 PAT。有和没有凭证管理器。正在调查...

以上是关于无法 git push,致命:身份验证失败,用户名更改后的主要内容,如果未能解决你的问题,请参考以下文章

远程:无效的用户名或密码。致命:身份验证失败

Azure Devops OnPremise,致命:克隆 Git 存储库时身份验证失败

psql:致命:用户的 PAM 身份验证失败

连接到 gitlab 时使用 ssh 面临身份验证失败

PostgreSQL - 致命:用户的身份验证失败

psql:致命:用户“postgres”的身份验证失败