无法更改 Git 个帐户

Unable to change Git account

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

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

之前,我使用的用户名是edgarphan,但我已经将其更改为PhanVanLinh,但它仍然保留edgarphan

我试过删除项目并重新克隆,卸载Git并重新安装,但是没有用。

全局配置文件

我该如何解决这个问题?

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

C:\Users\<user_name>\.gitconfig

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

git config --global -e

设置配置后,执行:

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

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

如果 Git 没有 询问您的 GitHub(新)username/password,这意味着 Git for Windows 是使用名为“manager”的 Git 凭据助手(执行 git config credential.helper 确认)

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

在这种情况下,转到 Windows 开始菜单 (), type "credential" and select the Windows tool "Windows Credential Manager".

在其中,您会找到一个可以编辑的条目 git.https://github.com,您可以在其中输入新的 Git 中心 username/password。

然后再次尝试推送。


使用更新的 Git 版本(2.32+,2021 年第 2 季度),假设 <C:\path\to\git>\usr\bin<C:\path\to\git>\mingw64\libexec\git-core 在您的 %PATH% 中,您可以在命令行:

printf "protocol=https\nhost=github.com\nusername=xxx"| git-credential-manager-core erase

我遇到了同样的问题,我没有为 git 设置用户名和密码,以下解决了我的问题。

注意:如果您为 GitHub 启用双重身份验证,请暂时禁用它

  • 步骤 01
Goto Control Panel -> User Accounts -> Credential Manager -> Windows Credentials
  • 步骤 02
Goto Generic Credentials section -> Add a generic credential
  • 步骤 03 - 填写字段
Internet or network address : git.https://github.com
User name                   : your github username
Password                    : your github username

现在点击确定。这将解决无法推送存储库的问题