无法更改Git帐户

问题描述 投票:0回答:4

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

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 github window
4个回答
70
投票

这与您的

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

如果 Git 要求您提供 GitHub(新)用户名/密码,则意味着 Git for Windows 正在使用名为“manager”的 Git 凭证助手(执行

git config credential.helper
进行确认)

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

在这种情况下,请转到 Windows 开始菜单 (),键入“凭据”并选择 Windows 工具“Windows 凭据管理器”。

在其中,您将找到一个条目

git.https://github.com
,您可以编辑该条目,并可以在其中输入新的 GitHub 用户名/密码。

然后再次尝试推动。


使用更新的 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

1
投票

尝试找出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

1
投票

我遇到了同样的问题,我没有设置 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

现在单击“确定”。这样就解决了推送仓库失败的问题


0
投票

我有一个类似的问题,但它是在我使用 SSH 克隆的存储库上。我在

id_rsa
中有一个旧的
C:\Users\[User]\.ssh
文件,现在 Github 建议您使用
id_ed25519
,但
id_rsa
会覆盖
id_ed25519
。所以,我不得不删除
id_rsa
id_rsa.pub

© www.soinside.com 2019 - 2024. All rights reserved.