【发布时间】:2014-05-15 16:55:18
【问题描述】:
我在终端中推拉 git,然后我在 github.com 上更改了我的用户名。我去推送一些更改,但它无法推送,因为它仍在识别我的旧用户名。我如何在终端的 git 上更改/更新我的用户名?
【问题讨论】:
标签: git github git-config
我在终端中推拉 git,然后我在 github.com 上更改了我的用户名。我去推送一些更改,但它无法推送,因为它仍在识别我的旧用户名。我如何在终端的 git 上更改/更新我的用户名?
【问题讨论】:
标签: git github git-config
您可能需要更新远程 URL,因为 github 将您的用户名放入其中。您可以通过键入
查看原始 URLgit config --get remote.origin.url
或者直接访问 Github 上的存储库页面并获取新 URL。然后使用
git remote set-url origin https://{new url with username replaced}
用您的新用户名更新 URL。
【讨论】:
git 命令时运行。没有需要重新启动的 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,您需要打开计算机(Win 或 Mac)的凭据管理器并在那里更新凭据
疑难解答? Learn more
【讨论】:
--local,您可以在同一台计算机上的特定存储库中使用不同的凭据。 (例如,您想从您的工作笔记本电脑提交您的个人仓库,但在其他仓库中使用您的工作凭据登录。)
git config credential.username "xxx"
git config user.name "Full Name" 设置我的正确用户名之后。当我通过git config --list 检查我的配置时,列表中有两个 user.name 记录。前者是不需要的,后者是我通过 git config 命令设置的。可悲的是,如果我进行提交,则会应用错误的提交。
[ ] 括号以获取--global 配置。方括号只表示您可以决定是否接受。
请更新新的用户存储库 URL
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 credential.username "new_username"
改变全局使用
git config --global credential.username "new_username"
(EDIT EXPLAINED:如果您不更改user.email 和user.name,您将能够推送您的更改,但它们将在前一个用户下的 git 中注册)
下次您push时,系统会要求您输入密码
Password for 'https://<new_username>@github.com':
【讨论】:
git config user.name "xxx" -> git config user.email "xxx" -> git config credential.username "xxx"
config git config --global credential.username "new_username" 之后
--unset,例如git config user.email --unset
我建议您只需转到 .git 文件夹,然后打开 config 文件即可。在文件中粘贴您的用户信息:
[user]
name = Your-Name
email = Your-email
应该就是这个了。
【讨论】:
有 3 种方法可以解决此问题
要设置您帐户的默认身份globally,请运行以下命令
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git config --global user.password "your password"
要仅在当前存储库中设置身份,请删除 --global 并在您的 Project/Repo 根目录中运行以下命令
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
注意:如果您不在代理后面,则可以从上面删除代理行
创建 .gitconfig 文件的主目录:
windows : c/users/
Mac 或 Linux: 运行此命令进入主目录cd ~
或者干脆一个接一个地运行以下命令
git config --global --edit
git commit --amend --reset-author
窗口:
Control Panel >> User Account >> Credential Manager >> Windows Credential >> Generic Credential
>> look for any github cert/credential and delete it.
然后运行任何 git 命令将提示输入新用户名和 密码。
苹果机:
command+space >> search for "keychain Access" and click ok >>
search for any certificate/file with gitHub >> delete it.
然后运行任何 git 命令将提示输入新用户名和 密码。
【讨论】:
git config user.name 和git config user.password,在任何push 之后都需要用户名和密码
如果你已经创建了一个新的 Github 账户,并且你想用你的新账户而不是你以前的账户推送提交,那么 .gitconfig 必须更新,否则,你将使用已经拥有的 Github 账户推送到新账户。
为了解决这个问题,您必须导航到您的主目录并使用编辑器打开 .gitconfig。编辑器可以是vim,notepad++,甚至notepad。
打开 .gitconfig 后,只需使用您要推送的新 Github 帐户用户名修改“名称”。
【讨论】:
从您的终端执行:
git config credential.username "prefered username"
或
git config --global user.name "Firstname Lastname"
【讨论】:
通常用户名位于 git config 下
git config --global user.name "first last"
虽然如果你仍然看到上面不起作用,你可以在你的 mac 用户目录下编辑 .gitconfig 并更新
[user]
name = gitusername
email = xyz@xyz.com
【讨论】:
如果您使用包含您的用户名的 url 克隆了您的 repo,那么您还应该更改 remote.origin.url 属性,否则它会一直询问旧用户名的密码。
示例:
remote.origin.url=https://<old_uname>@<repo_url>
应该改为
remote.origin.url=https://<new_uname>@<repo_url>
【讨论】:
**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.**
【讨论】:
git config [--global] user.name "Full Name"
git config [--global] user.email "email@address.com"
您也可以根据 repo 手动编辑 .git/config。
在执行第 2 步时,如果您看到 credential.helper=manager,您需要打开计算机(Win 或 Mac)的凭据管理器并在那里更新凭据
【讨论】:
您可以在终端中使用此命令更改当前 git 用户
$ git config --global user.name "Bob"
$ git config --global user.email "bob@example.com"
【讨论】:
我自己最近也遇到了同样的问题。就我而言,我有两个 github 帐户:工作帐户和个人帐户。我想将我的起始代码推送到我的个人帐户中的存储库,但全局配置有我的工作帐户。我不想每次不得不在工作和个人项目之间切换时都重新配置全局。所以我使用这些命令为那个特定的个人项目文件夹设置我的用户名和电子邮件。
解决办法:
$ git config user.name "Alex"
$ git config user.email "Alex@example.com"
$ git config credential.username "your_account_name_here"
【讨论】:
在 linux (Ubuntu 18.04) 中,are saved as cleartext 文件中的用户名/密码 ~/.git-credentials,只需编辑文件以使用您的新用户名/密码。
文件格式非常简单,每一行都包含一个用户/域的凭据,格式如下:
https://<username>:<password>@github.com
https://<username2>:<password2>@bitbucket.com
...
【讨论】: