问题
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 my old username.. How do I change/update my username on git in terminal?
回答1:
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.
回答2:
- In your terminal, navigate to the repo you want to make the changes in.
- Execute
git config --list
to check current username & email in your local repo. - Change username & email as desired. Make it a global change or specific to the local repo:
git config [--global] user.name "Full Name"
git config [--global] user.email "email@address.com"
Per repo basis you could also edit.git/config
manually instead. - Done!
When performing step 2 if you see credential.helper=manager
you need to open the credential manager of your computer (Win or Mac) and update the credentials there
Here is how it look on windows
Troubleshooting? Learn more
回答3:
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 credential.username --global "new_username"
(EDIT EXPLAINED: If you don't change also the
user.email
anduser.name
, you will be able to push your changes, but they will be registered in git under the previous user)Next time you
push
, you will be asked to enter your passwordPassword for 'https://<new_username>@github.com':
回答4:
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
回答5:
Please update new user repository URL
git remote set-url origin https://username@bitbucket.org/repository.git
I tried using below commands, it's not working:
git config user.email "email@example.com"
git config user.name "user"
OR
git config --global user.email "email@example.com"
git config --global user.name "user"
回答6:
From your terminal do:
git config credential.username "prefered username"
OR
git config --global user.name "Firstname Lastname"
回答7:
I recommend you to do this by simply go to your .git folder, then open config file. In the file paste your user info:
[user]
name = Your-Name
email = Your-email
This should be it.
回答8:
There is a easy solution for that problem, the solution is removed the certificate the yours Keychain, the previous thing will cause that it asks again to the user and password.
Steps:
- Open keychain access
Search the certificate gitHub.com.
Remove gitHub.com certificate.
Execute any operation with git in your terminal. this again ask your username and password.
回答9:
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.
来源:https://stackoverflow.com/questions/22844806/how-to-change-my-git-username-in-terminal