我在终端推送和拉动git然后我在github.com上更改了我的用户名。我去推了一些更改,它无法推送,因为它仍然识别我的旧用户名..如何在终端上的git上更改/更新我的用户名?
您可能需要更新远程URL,因为github会将您的用户名放入其中。您可以通过键入来查看原始URL
git config --get remote.origin.url
或者只是转到Github上的存储库页面并获取新的URL。然后用
git remote set-url origin https://{new url with username replaced}
使用新用户名更新网址。
git config --list
以检查当地仓库中的当前用户名和电子邮件。git config [--global] user.name "Full Name"
git config [--global] user.email "[email protected]"
根据每个回购基础,您也可以手动编辑.git/config
。故障排除? Learn more
git config credential.username "new_username"
改变全球使用
git config credential.username --global "new_username"
(编辑解释:如果你不改变user.email
和user.name
,你将能够推动你的更改,但它们将在以前用户的git中注册)push
,你会被要求输入你的密码
Password for 'https://<new_username>@github.com':
要设置帐户的默认身份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"
请更新新的用户存储库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"
从您的终端做:
git config credential.username "prefered username"
要么
git config --global user.name "Firstname Lastname"
我建议您只需转到.git文件夹,然后打开配置文件即可。在文件中粘贴您的用户信息:
[user]
name = Your-Name
email = Your-email
这应该是它。
如果您已创建新的Github帐户,并且想要使用新帐户而不是之前的帐户推送提交,则必须更新.gitconfig,否则您将使用已拥有的Github帐户推送到新帐户。
要解决此问题,您必须导航到主目录并使用编辑器打开.gitconfig。编辑器可以是vim,notepad ++甚至是记事本。
打开.gitconfig后,只需使用要推送的新Github帐户用户名修改“名称”即可。