我的旧用户名仍在使用中

MAS*_*MAS 0 git github

我用这些命令改变了我的用户和电子邮件git

git config --global user.name "maa"
git config user.email "maa@gmail.com"
Run Code Online (Sandbox Code Playgroud)

我确认了这一变化

git config --global user.name
git config user.email
Run Code Online (Sandbox Code Playgroud)

它显示正确的名称.但是,当我按下旧用户名时使用:

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
Run Code Online (Sandbox Code Playgroud)

MrT*_*Tux 6

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

我可以看到你正在使用https传输,所以用户名以某种方式存储.在我看来,有两种选择:

  1. 您正在使用%HOME%/.netrc(%HOME%/_netrc%HOMEDRIVE%%HOMEPATH%\_netrc在Windows上)
  2. 您的用户名包含在push-url中(例如https://username@github.com/...),您需要在此处更新.git/config,例如通过发布git remote set-url https://<newusername>@github.com/<newusername>/yourRepo
  3. 您正在使用git凭证帮助程序.这取决于您使用的是哪一个(也许您使用的操作系统,请参阅Windows,Mac OS X).

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

$ git credential-$credentialhelper erase
host=github.com
protocol=https
[Press Return]
Run Code Online (Sandbox Code Playgroud)