How to change my Git username in terminal?

后端 未结 13 1857
予麋鹿
予麋鹿 2020-12-07 07:17

I was pushing and pulling from git in Terminal then I changed my username on github.com. I went to push some changes and it couldn\'t push because it was still recognizing

13条回答
  •  醉酒成梦
    2020-12-07 07:30

    method-1 (command line)

    To set your account's default identity globally run below commands

    git config --global user.email "you@example.com"
    git config --global user.name "Your Name"
    git config --global user.password "your password"
    

    To set the identity only in current repository , remove --global and run below commands in your Project/Repo root directory

    git config user.email "you@example.com"
    git config user.name "Your Name"
    git config user.password "your password"
    

    Example:

    email -> organization email Id
    name  -> mostly  or  
    

    **Note: ** you can check these values in your GitHub profile or Bitbucket profile

    method-2 (.gitconfig)

    create a .gitconfig file in your home folder if it doesn't exist. and paste the following lines in .gitconfig

    [user]
        name = FirstName, LastName
        email = FirstName.LastName@company.com
    [http]
        sslVerify = false
        proxy = 
    [https]
        sslverify = false
        proxy = https://corp\\:@:
    [push]
        default = simple
    [credential]
        helper = cache --timeout=360000000
    [core]
        autocrlf = false
    

    Note: you can remove the proxy lines from the above , if you are not behind the proxy

    Home directory to create .gitconfig file:

    windows : c/users/< username or empID >

    Mac or Linux : run this command to go to home directory cd ~

    or simply run the following commands one after the other

    git config --global --edit
    git commit --amend --reset-author
    

    method-3 (git credential pop up)

    windows :

    Control Panel >> User Account >> Credential Manager >> Windows Credential >> Generic Credential

    look for any github cert/credential and delete it.

    Mac :

    command+space >> search for "keychain Access" and click ok >> search for any certificate/file with gitHub >> delete it.

    then running any git command will prompt to enter new user name and password.

提交回复
热议问题