我在终端中使用git进行推送和拉取,然后我在github.com上更改了我的用户名。当我尝试推送一些更改时,由于仍然识别我的旧用户名,因此无法进行推送。如何在终端中更改/更新我的git用户名?
我在终端中使用git进行推送和拉取,然后我在github.com上更改了我的用户名。当我尝试推送一些更改时,由于仍然识别我的旧用户名,因此无法进行推送。如何在终端中更改/更新我的git用户名?
针对 Github
git config --local user.name "another_username"
git config --local user.email "email@example.com"
git remote set-url origin https://another_username@github.com/repo_url
git config [--global] user.name "姓名"
git config [--global] user.email "email@address.com"
对于每个仓库,您还可以手动编辑 .git/config
文件。
在执行第2步时,如果看到 credential.helper=manager
,您需要打开计算机的凭据管理器 (Windows 或 Mac),并在其中更新凭据。
我最近也面临了同样的问题。在我的情况下,我有两个 GitHub 账户:工作和个人账户。我想将我的起始代码推送到个人账户的仓库中,但是全局配置使用的是我的工作账户。我不想每次切换工作和个人项目时都要重新配置全局设置。因此,我使用以下命令为该特定的个人项目文件夹设置了用户名和电子邮件。
解决方案:
$ git config user.name "Alex"
$ git config user.email "Alex@example.com"
$ git config credential.username "your_account_name_here"
~/.git-credentials
中,只需编辑该文件以使用新的用户名/密码。https://<username>:<password>@github.com
https://<username2>:<password2>@bitbucket.com
...
git config --global user.name "first last"
如果您仍然发现上述方法不起作用,您可以编辑位于Mac用户目录下的.gitconfig文件并进行更新。
[user]
name = gitusername
email = xyz@xyz.com
如果您已经创建了一个新的Github账户,并且想要使用新账户而不是之前的账户推送提交,则必须更新.gitconfig文件,否则您将使用已拥有的Github账户向新账户推送。
为了解决这个问题,您需要进入您的主目录并使用编辑器打开.gitconfig文件。编辑器可以是vim、notepad++或者甚至是记事本。
一旦您打开了.gitconfig文件,只需使用您想要推送的新Github账户用户名修改“name”即可。
remote.origin.url
属性,否则它会继续要求旧用户名的密码。remote.origin.url=https://<old_uname>@<repo_url>
应该改为
remote.origin.url=https://<new_uname>@<repo_url>
ERROR: Permission to <repo>.git denied to <username_2>.
fatal: Could not read from remote repository.
ssh-add -d ~/.ssh/<username_2_key>
ssh-add -d ~/.ssh/<username_1_key>
ssh-add -D
命令来删除所有身份标识。
gitconfig
的问题。 - Scrooge McDuck