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


当前回答

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

解决方案:

$ git配置用户名

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

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

其他回答

从你的终端做:

git config credential.username "prefered username"

OR

git config --global user.name "Firstname Lastname"

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

我建议你只需转到你的。git文件夹,然后打开配置文件。在文件中粘贴您的用户信息:

[user]
    name = Your-Name
    email = Your-email

应该就是这个了。

在linux (Ubuntu 18.04)中,用户名/密码以明文形式保存在文件~/中。Git-credentials,只需编辑文件以使用您的新用户名/密码。

文件格式非常简单,每行包含一个用户/域的凭据,格式如下:

https://<username>:<password>@github.com
https://<username2>:<password2>@bitbucket.com
...

我们有三种方法可以解决这个问题

方法-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拉)。