如何在终端中更改我的Git用户名?

问题描述 投票:59回答:9

我在终端推送和拉动git然后我在github.com上更改了我的用户名。我去推了一些更改,它无法推送,因为它仍然识别我的旧用户名..如何在终端上的git上更改/更新我的用户名?

git github git-config
9个回答
62
投票

您可能需要更新远程URL,因为github会将您的用户名放入其中。您可以通过键入来查看原始URL

git config --get remote.origin.url

或者只是转到Github上的存储库页面并获取新的URL。然后用

git remote set-url origin https://{new url with username replaced}

使用新用户名更新网址。


64
投票
  1. 在终端中,导航到要进行更改的仓库。
  2. 执行git config --list以检查当地仓库中的当前用户名和电子邮件。
  3. 根据需要更改用户名和电子邮件使其成为全局变更或特定于本地仓库: git config [--global] user.name "Full Name" git config [--global] user.email "[email protected]" 根据每个回购基础,您也可以手动编辑.git/config
  4. 完成!

故障排除? Learn more


39
投票
  1. 编辑:除了更改您的姓名和电子邮件您可能还需要更改您的凭据: 要仅在一个存储库中进行本地更改,请从存储库中输入终端 git config credential.username "new_username" 改变全球使用 git config credential.username --global "new_username" (编辑解释:如果你不改变user.emailuser.name,你将能够推动你的更改,但它们将在以前用户的git中注册)
  2. 下次你push,你会被要求输入你的密码 Password for 'https://<new_username>@github.com':

16
投票

要设置帐户的默认身份globally,请执行以下命令

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

要仅在当前存储库中设置标识,请删除--global并在Project / Repo根目录中运行以下命令

git config user.email "[email protected]"
git config user.name "Your Name"

13
投票

请更新新的用户存储库URL

 git remote set-url origin https://[email protected]/repository.git

我尝试使用下面的命令,它不起作用:

git config user.email "[email protected]"
git config user.name  "user"

要么

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

8
投票

从您的终端做:

git config credential.username "prefered username"

要么

git config --global user.name "Firstname Lastname"

2
投票

我建议您只需转到.git文件夹,然后打开配置文件即可。在文件中粘贴您的用户信息:

[user]
    name = Your-Name
    email = Your-email

这应该是它。


2
投票

对于那个问题有一个简单的解决方案,解决方案是删除你的钥匙串证书,之前的事情将导致它再次询问用户和密码。

脚步:

  1. 打开钥匙串访问

enter image description here

  1. 搜索证书gitHub.com。
  2. 删除gitHub.com证书。
  3. 在终端中使用git执行任何操作。再次询问您的用户名和密码。

0
投票

如果您已创建新的Github帐户,并且想要使用新帐户而不是之前的帐户推送提交,则必须更新.gitconfig,否则您将使用已拥有的Github帐户推送到新帐户。

要解决此问题,您必须导航到主目录并使用编辑器打开.gitconfig。编辑器可以是vim,notepad ++甚至是记事本。

打开.gitconfig后,只需使用要推送的新Github帐户用户名修改“名称”即可。

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