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


当前回答

请更新新用户存储库URL

 git remote set-url origin https://username@bitbucket.org/repository.git

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

git config user.email "email@example.com"
git config user.name  "user"

OR

git config --global user.email "email@example.com"
git config --global user.name "user"

其他回答

请更新新用户存储库URL

 git remote set-url origin https://username@bitbucket.org/repository.git

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

git config user.email "email@example.com"
git config user.name  "user"

OR

git config --global user.email "email@example.com"
git config --global user.name "user"

你可能需要更新远程URL,因为github把你的用户名放在里面。您可以通过键入来查看原始URL

git config --get remote.origin.url

或者只是去Github上的存储库页面,并获得新的URL。然后使用

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

用你的新用户名更新网址。

编辑:除了更改您的姓名和电子邮件,您可能还需要更改您的证书:

若要仅为一个存储库进行本地更改,请从存储库中输入terminal Git配置凭证。用户名“new_username” 改变全球使用 Git配置——全局凭据。用户名“new_username” (编辑解释:如果你不改变也用户。Email和user.name,你将能够推送你的更改,但它们将在git中注册在前一个用户下)

下次你再按,系统会要求你输入密码 “https://<new_username>@github.com”的密码:

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

我自己最近也面临着同样的问题。在我的情况下,我有两个github账户:工作和个人。我想把我的启动器代码推到我个人帐户的存储库中,但全局配置有我的工作帐户。我不想每次在工作和个人项目之间切换时都重新配置全局。因此,我使用这些命令为特定的个人项目文件夹设置用户名和电子邮件。

解决方案:

$ git配置用户名

$ git config user.email “Alex@example.com”

$ git配置凭证。用户名“your_account_name_here”