无法更改 Git 帐户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46629838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:55:37  来源:igfitidea点击:

Unable to change Git account

gitgithubwindow

提问by Phan Van Linh

I tried to push to my repository, but I got the error below:

我试图推送到我的存储库,但出现以下错误:

git push origin master
remote: Permission to PhanVanLinh/phanvanlinh.github.io.git denied to edgarphan.
fatal: unable to access 'https://github.com/PhanVanLinh/phanvanlinh.github.io.git/': The requested URL returned error: 403

Before, I was using username edgarphan, but I have already changed it to PhanVanLinh, but it still keeps edgarphan.

之前,我使用 username edgarphan,但我已经将其更改为PhanVanLinh,但它仍然保留edgarphan.

I have tried to delete the project and clone again, uninstall Git and reinstall, but it won't work.

我试图删除项目并再次克隆,卸载 Git 并重新安装,但它不起作用。

Enter image description here

在此处输入图片说明

Global configuration file

全局配置文件

Enter image description here

在此处输入图片说明

How can I fix this issue?

我该如何解决这个问题?

回答by VonC

This has nothing to do with your user.name/user.emailsettings: those are for authorship in a commit. They are notused for authentication when you push to a repo.

这与您的user.name/user.email设置无关:那些用于提交中的作者身份。当您推送到存储库时,它们用于身份验证。

If Git does notask you for your GitHub (new) username/password, that means Git for Windowsis using a Git credential helper called "manager" (do a git config credential.helperto confirm it)

如果 Git没有要求您提供 GitHub(新)用户名/密码,则表示Windows 版 Git正在使用名为“manager”的 Git 凭据帮助程序(执行 agit config credential.helper以确认)

Meaning: it is caching your old credentials and is reusing them automatically.

含义:它正在缓存您的旧凭据并自动重用它们。

In that case, go to the Windows start menu (Windows start), type "credential" and select the Windows tool "Windows Credential Manager".
enter image description here
In it, you will find an entry git.https://github.com, which you can edit, and where you can enter your new GitHub username/password. Enter new credentials

在这种情况下,请转到 Windows 开始菜单 ( 视窗启动),键入“凭据”并选择 Windows 工具“ Windows 凭据管理器”。 在其中,您会找到一个条目,您可以对其进行编辑,并且您可以在其中输入新的 GitHub 用户名/密码。
在此处输入图片说明
git.https://github.com输入新凭据

Then try and push again.

然后再次尝试推动。

回答by unreleased

Try to find out the Git configuration file. For a Windows machine it probably located at

尝试找出 Git 配置文件。对于 Windows 机器,它可能位于

C:\Users\<user_name>\.gitconfig

C:\Users\<user_name>\.gitconfig

This command may open up the configuration file too. Then you can just edit and save:

这个命令也可以打开配置文件。然后你可以编辑并保存:

git config --global -e

git config --global -e

And after setting the configuration, do:

并在设置配置后,执行:

cd /path/to/new/local/repo
git remote add origin https://github.com/PhanVanLinh/phanvanlinh.github.io.git
git push -u origin master