git 我的旧用户名仍在使用中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39944469/
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:20:13  来源:igfitidea点击:

my old username is still in use

gitgithub

提问by MAS

I have changed my user and email for git with those commands

我已经使用这些命令更改了 git 的用户和电子邮件

git config --global user.name "maa"
git config user.email "[email protected]"

I confirmed the change with

我确认了更改

git config --global user.name
git config user.email

and it shows the right names. However when I push the old user name is used:

它显示了正确的名称。但是,当我推送旧用户名时使用:

git push -u origin master
remote: Permission to maa/brain.git denied to old_user_name.
fatal: unable to access 'https://github.com/maa/brain.git/': The requested URL returned error: 403

回答by MrTux

The user.nameand user.emailsettings are only used for commit meta data.

user.nameuser.email设置仅用于提交的元数据。

As I can see you are using https transport, so the username is stored somehow. To my mind there are two options:

正如我所看到的,您正在使用 https 传输,因此以某种方式存储了用户名。在我看来,有两种选择:

  1. You are using %HOME%/.netrc(%HOME%/_netrcor %HOMEDRIVE%%HOMEPATH%\_netrcon Windows)
  2. Your username is included in the push-url (like https://[email protected]/...), here you need to update .git/config, e.g. by issuing git remote set-url https://<newusername>@github.com/<newusername>/yourRepo
  3. You are using a git credential helper. Here it depends which one you use (and maybe which OS you use, see for Windows, Mac OS X).
  1. 您正在使用%HOME%/.netrc%HOME%/_netrc%HOMEDRIVE%%HOMEPATH%\_netrc在 Windows 上)
  2. 您的用户名包含在 push-url 中(如https://[email protected]/...),在这里您需要更新.git/config,例如通过发出git remote set-url https://<newusername>@github.com/<newusername>/yourRepo
  3. 您正在使用 git 凭证助手。这取决于您使用的是哪一个(也许您使用的是哪个操作系统,请参阅 WindowsMac OS X)。

As a general rule you can try the following on the CLI (based on 2), where you replace $credentialhelperwith your credential-helper (you can find it using git config credential.helper, for Mac OS X it is likely osxkeychainon Windows it might be wincredor manager):

作为一般规则,您可以在 CLI(基于2)上尝试以下操作,在其中替换$credentialhelper为您的凭证助手(您可以使用 找到它git config credential.helper,对于 Mac OS X,它可能osxkeychain在 Windows 上可能是wincredmanager):

$ git credential-$credentialhelper erase
host=github.com
protocol=https
[Press Return]