【问题标题】:Unable to change Git account无法更改 Git 帐户
【发布时间】:2018-03-19 16:23:02
【问题描述】:

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

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 config --global user.name怎么样
  • @unreleased git config --global user.name 也是PhanVanLinh
  • 您的图片未显示

标签: git github window


【解决方案1】:

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

如果 Git不 询问您的 GitHub(新)用户名/密码,这意味着 Git for Windows 正在使用名为“manager”的 Git 凭证助手(使用 git config credential.helper 进行确认) )

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

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

在其中,您将找到一个条目 git.https://github.com,您可以对其进行编辑,并且您可以在其中输入新的 GitHub 用户名/密码。

然后再次尝试推送。


对于较新的 Git 版本(2.32+,2021 年第二季度),假设 <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

【讨论】:

  • 删除凭据解决了我的问题。我在这个问题上停留了很多天,并且曾经认为我会在窗户上出现鬼影。非常感谢,你救了我。
  • 同样,这帮了很大的忙。
  • 你救了我兄弟
  • @SeakyLone 比请提出一个单独的问题,提供有关您当前设置的更多详细信息。例如,如果您的远程 URL 是 SSH 而不是 HTTPS,那么您实际上不会在凭证管理器中看到任何内容(因为它只处理 HTTPS 查询的凭证)
  • 非常感谢..完美的解决方案
【解决方案2】:

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

【讨论】:

  • 我试过了,我收到了和我的问题一样的错误。
【解决方案3】:

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

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

【讨论】:

    猜你喜欢
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-02
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    • 2019-03-02
    • 1970-01-01
    相关资源
    最近更新 更多