我从终端的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}
用你的新用户名更新网址。
其他回答
如果你已经创建了一个新的Github帐户,并且你想用你的新帐户而不是以前的帐户推送提交,那么.gitconfig必须更新,否则,你将用已经拥有的Github帐户推送到新帐户。
为了解决这个问题,您必须导航到您的主目录并用编辑器打开.gitconfig。编辑器可以是vim, notepad++,甚至notepad。
打开.gitconfig后,只需用你想要推送的新Github帐户用户名修改“名称”。
我们有三种方法可以解决这个问题
方法-1(命令行)
要全局设置帐户的默认标识,请运行以下命令
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配置文件中检查这些值
方法2 (.gitconfig)
在主文件夹中创建一个.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/< username或empID >
Mac和Linux:执行该命令进入主目录cd ~
或者简单地一个接一个地运行以下命令
git config --global --edit
git commit --amend --reset-author
方法-3(弹出git凭据)
窗口:
Control Panel >> User Account >> Credential Manager >> Windows Credential >> Generic Credential
>> look for any github cert/credential and delete it.
然后运行任何git命令将提示输入新用户名和 密码(注意:有时你不会提示密码git拉)。
麦克:
command+space >> search for "keychain Access" and click ok >>
search for any certificate/file with gitHub >> delete it.
然后运行任何git命令将提示输入新用户名和 密码(注意:有时你不会提示密码git拉)。
我建议你只需转到你的。git文件夹,然后打开配置文件。在文件中粘贴您的用户信息:
[user]
name = Your-Name
email = Your-email
应该就是这个了。
编辑:除了更改您的姓名和电子邮件,您可能还需要更改您的证书:
若要仅为一个存储库进行本地更改,请从存储库中输入terminal Git配置凭证。用户名“new_username” 改变全球使用 Git配置——全局凭据。用户名“new_username” (编辑解释:如果你不改变也用户。Email和user.name,你将能够推送你的更改,但它们将在git中注册在前一个用户下)
下次你再按,系统会要求你输入密码 “https://<new_username>@github.com”的密码:
如果你使用包含你的用户名的url克隆了你的repo,那么你也应该改变remote.origin.url属性,否则它会一直询问旧用户名的密码。
例子:
remote.origin.url=https://<old_uname>@<repo_url>
应改为
remote.origin.url=https://<new_uname>@<repo_url>
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 在GitHub上有一个公共回购的私人分支?
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- 只用GitHub动作在特定分支上运行作业
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 是否有一个链接到GitHub下载文件的最新版本的存储库?