我在终端中使用git进行推送和拉取,然后我在github.com上更改了我的用户名。当我尝试推送一些更改时,由于仍然识别我的旧用户名,因此无法进行推送。如何在终端中更改/更新我的git用户名?
我在终端中使用git进行推送和拉取,然后我在github.com上更改了我的用户名。当我尝试推送一些更改时,由于仍然识别我的旧用户名,因此无法进行推送。如何在终端中更改/更新我的git用户名?
git config --list
命令以检查本地存储库中当前的用户名和电子邮件。git config [--global] user.name "Full Name"
git config [--global] user.email "email@address.com"
.git/config
文件来进行更改。执行步骤2时,如果看到 credential.helper=manager
,则需要打开计算机的凭据管理器(Windows 或 Mac),并在那里更新凭据。
有疑问? 了解更多
--local
参数,在同一台电脑上可以在不同的代码库中使用不同的凭据(例如,你可以使用个人仓库的凭据在工作笔记本上提交代码,但同时在其他代码库中保持工作凭据登录状态)。 - Xeraqugit config user.name "Full Name"
设置正确的用户名后,当我通过git config --list
检查我的配置时,列表中会出现两个user.name记录。前一个是不需要的,而后一个则是我通过git config命令设置的。不幸的是,如果我进行提交,将会应用错误的记录。 - webpreneur[ ]
括号即可获得 --global
配置。这些括号仅表示您可以选择采用此选项或不采用。 - questionto42你可能需要更新远程URL,因为GitHub会在其中放置您的用户名。您可以通过键入以下内容查看原始URL:
git config --get remote.origin.url
或者直接前往Github上的存储库页面获取新的URL。然后使用该URL即可。
git remote set-url origin https://{new url with username replaced}
更新URL以显示您的新用户名。
git
命令时,git才会运行。没有需要重新启动的git服务。您是否使用双重身份验证或其他奇怪的东西? - Steven V我们可以通过以下3种方法解决这个问题。
要在全局范围内设置您账户的默认标识,请运行以下命令:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git config --global user.password "your password"
如果只想在当前代码库中设置身份,请删除--global
并在您的项目/代码库根目录下运行以下命令:
git config user.email "you@example.com"
git config user.name "Your Name"
git config user.password "your password"
例子:
email -> organization email Id
name -> mostly <employee Id> or <FirstName, LastName>
注意:你可以在GitHub资料页面或Bitbucket资料页面查看这些值
如果不存在,请在主目录中创建一个.gitconfig文件,并将以下行粘贴到.gitconfig中。
[user]
name = FirstName, LastName
email = FirstName.LastName@company.com
password = abcdxyz
[http]
sslVerify = false
proxy =
[https]
sslverify = false
proxy = https://corp\\<uname>:<password>@<proxyhost>:<proxy-port>
[push]
default = simple
[credential]
helper = cache --timeout=360000000
[core]
autocrlf = false
git config --global --edit
git commit --amend --reset-author
Windows:
Control Panel >> User Account >> Credential Manager >> Windows Credential >> Generic Credential
>> look for any github cert/credential and delete it.
command+space >> search for "keychain Access" and click ok >>
search for any certificate/file with gitHub >> delete it.
运行任何git命令将提示输入新的用户名和密码(注意:有时您在进行git pull操作时不需要输入密码)。
要仅更改一个存储库的本地设置,请在终端中输入,从存储库内部开始:
git config credential.username "new_username"
要全局更改,请使用
git config --global credential.username "new_username"
(编辑解释: 如果您不更改 user.email
和 user.name
,您可以推送您的更改,但它们将在 git 中注册为之前的用户)
下次您执行 push
操作时,系统会要求您输入密码
'https://<new_username>@github.com' 的密码:
git config user.name "xxx"->
git config user.email "xxx"->
git config credential.username "xxx"` - Fernando Wittmannconfig
之后,即:git config --global credential.username "new_username"
- Caleb Rotich--unset
,例如 git config user.email --unset
。 - DalyaG git remote set-url origin https://username@bitbucket.org/repository.git
我尝试使用以下命令,但它们不起作用:
git config user.email "email@example.com"
git config user.name "user"
或者
git config --global user.email "email@example.com"
git config --global user.name "user"
我建议你通过前往你的.git文件夹并打开config文件来完成此操作。在文件中粘贴你的用户信息:
[user]
name = Your-Name
email = Your-email
这应该就是了。
从您的终端执行以下操作:
git config credential.username "prefered username"
或者
git config --global user.name "Firstname Lastname"
**Check by executing this**
git config --list
**Change user email**
git config --global user.email "email@example.com"
**Change user name**
git config --global user.name "user"
**Change user credential name**
git config --global credential.username "new_username"
**After this a window popup asking password.
Enter password and proceed.**
gitconfig
的问题。 - Scrooge McDuck