How to change my Git username in terminal?

后端 未结 13 1791
予麋鹿
予麋鹿 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:18
    1. EDIT: In addition to changing your name and email You may also need to change your credentials:
    • To change locally for just one repository, enter in terminal, from within the repository

      git config credential.username "new_username"
      
    • To change globally use

      git config --global credential.username "new_username"
      

      (EDIT EXPLAINED: If you don't change also the user.email and user.name, you will be able to push your changes, but they will be registered in git under the previous user)

    1. Next time you push, you will be asked to enter your password

      Password for 'https://<new_username>@github.com':

    0 讨论(0)
  • 2020-12-07 07:19

    You probably need to update the remote URL since github puts your username in it. You can take a look at the original URL by typing

    git config --get remote.origin.url
    

    Or just go to the repository page on Github and get the new URL. Then use

    git remote set-url origin https://{new url with username replaced}
    

    to update the URL with your new username.

    0 讨论(0)
  • 2020-12-07 07:19

    Firstly you need to change credentials from your local machine

    1. remove generic credentials if there is any

    1. configure new user and email (you can make it globally if you want)
    git config [--global] user.name "Your Name"
    git config [--global] user.email "email@address.com"
    
    1. now upload or update your repo it will ask your username and password to get access to github
    0 讨论(0)
  • 2020-12-07 07:19

    usually the user name resides under git config

    git config --global user.name "first last"
    

    although if you still see above doesn't work you could edit .gitconfig under your user directory of mac and update

    [user]
            name = gitusername
            email = xyz@xyz.com
    
    0 讨论(0)
  • 2020-12-07 07:20

    If you have created a new Github account and you want to push commits with your new account instead of your previous account then the .gitconfig must be updated, otherwise you will push with the already owned Github account to the new account.

    In order to fix this, you have to navigate to your home directory and open the .gitconfig with an editor. The editor can be vim, notepad++ or even notepad.

    Once you have the .gitconfig open, just modify the "name" with your new Github account username that you want to push with.

    0 讨论(0)
  • 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 <employee Id> or <FirstName, LastName> 
    

    **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\\<uname>:<password>@<proxyhost>:<proxy-port>
    [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.

    0 讨论(0)
提交回复
热议问题