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?
-
I think this [question](https://stackoverflow.com/a/43654115/9402438) to how setup per-project `gitconfig`s may be useful here. – Scrooge McDuck May 17 '22 at 14:24
-
Take a look at https://builditmasters.com/git-config-username-and-password-global/ – Osanda Gamage Jul 14 '22 at 10:14
17 Answers
- 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
-
68I'd like to point out for people that see this in the future, if you use `--local`, you can use different credentials in specific repositories on the same computer. (eg. you want to commit to your personal repo from your work laptop, but stay signed in with your work credentials in other repos.) – Xeraqu May 03 '18 at 14:01
-
3As mentioned by @DalyaG, the following should also be included: `git config credential.username "xxx"` – Fernando Wittmann Nov 02 '18 at 17:57
-
upvoting because of "edit .git/config manually". It was the best option in my case to change the remote.origin.url – Carlos Ost Mar 29 '19 at 11:59
-
3After setting my proper username with `git config user.name "Full Name"`. When I check my configuration via `git config --list` there are two user.name records in the list. The former one is the unwanted and latter is what I have set via the git config command. Sadly if I do a commit, the wrong one applies. – webpreneur Apr 27 '21 at 08:05
-
5For anyone new to this: remove the `[ ]` brackets to get the `--global` config. The brackets only say that you can decide to take this or not. – questionto42 Jan 27 '22 at 17:49
-
There is no git related generic credentials on my computer while I use git commit, push, pull everyday. Then how can we update the password? Please suggest. Thanks. – Kamlesh Jan 30 '22 at 08:36
-
2Hi @webpreneur. Check [this link](https://www.quora.com/Why-does-git-config-list-show-2-emails) to understand why do you have 2 usernames or emails. Basically it is saying that you have different config files so `--global`, `--local` and `--system`. So you are seeing the `--global` and `--local` ones. Type `git config --list --local` if you only want to see the local config just added – Bernat Oct 25 '22 at 08:31
-
Github documentation ([link](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-your-personal-account/managing-multiple-accounts)) says "If the output is `wincred`, you're using the Windows Credential Manager. To clear the credentials, enter the following command." Mine outputted `manager` so I thought mine wasn't using it. But after seeing this answer, I checked out Windows Credential Manager, and I see url for the test repositories I created... Wasted big time because of Github's poor documentation. – user3290525 Jan 03 '23 at 12:04
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.

- 16,357
- 3
- 63
- 76
-
Ok, I checked teh original url and it was using the old username, I went ahead and updated the url to reflect the new username and repository I'm in then it asks me for my username and password. I put in my credentials and it's saying fatal:Authentication failed remote: invalid username and password. I checked on github.com and signed with my account so I know those credentials are correct... Any thoughts? – user3370902 Apr 03 '14 at 17:43
-
@user3370902 I'd make sure you're using the right username and password first. Then also verify with the github repository page that you've got the URL correct. If you continue to have issues you may want to follow up with [Github Support](https://github.com/contact) since they'll be able to see exactly what's going on. – Steven V Apr 03 '14 at 17:46
-
3The username and password works when I logon to github.com - just not working in terminal.. Is there a way to close out terminal, log out/close down git, then restart git in terminal? – user3370902 Apr 03 '14 at 17:51
-
@user3370902 git only runs when you actually execute the `git` command at the command prompt. There's no git service that you need to restart. Do you use two factor authentication or any other weird things? – Steven V Apr 03 '14 at 17:55
-
Yes, I did set up 2 factor authentication with 2 phone numbers. Could this cause the issue? – user3370902 Apr 03 '14 at 17:56
-
1@user3370902 https://help.github.com/articles/providing-your-2fa-security-code near the bottom under "Through the command-line". You need to create an personal access token. – Steven V Apr 03 '14 at 18:02
-
Worked like a charm! Although, if I can NEVER see my token code after I create it, what happens when I need it again? Would I just delete and create a new one? – user3370902 Apr 03 '14 at 18:07
-
@user3370902 You should store that as you would a password. Maybe in a credential manager? There maybe one built into your operating system which git can store the password in for you if that's something you want. – Steven V Apr 03 '14 at 18:10
-
Wow. this answer saved a lot of my time. I had to write the entire url with the new password everytime. Pheww!! – Smit Yash Nov 26 '19 at 19:57
-
there are 3 ways we can fix this issue
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
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
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.
then running any git command will prompt to enter new user name and password (Note: some times you will not be prompted for password for git pull).
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(Note:some times you will not be prompted for password for git pull).

- 4,774
- 3
- 25
- 37
-
Even with adding `git config user.name` and `git config user.password` it requires username and password after any `push` – Benyamin Jafari Jan 25 '21 at 11:22
-
-
-
@BenyaminJafari for linux use the 2nd method. i tried it worked for me – sravan ganji May 11 '21 at 16:10
-
-
@BenyaminJafari you will be asked the password from terminal/command line ,when you run any git command (ex: git pull or git push) some times you will not be prompted for password for git pull but it will ask for git push – sravan ganji May 18 '21 at 16:31
-
@BenyaminJafari or you can keep the password in gitconfig > under User section but i would not recommend this approach – sravan ganji Jun 03 '21 at 11:49
-
-
- 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
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':
-
20Thank you! This should be in the top answer :) The following solved for me: ` `git config user.name "xxx"` -> `git config user.email "xxx"` -> `git config credential.username "xxx"` – Fernando Wittmann Nov 02 '18 at 17:55
-
13Global should come after `config` `git config --global credential.username "new_username"` – Caleb Rotich May 27 '19 at 09:36
-
-
1
-
Support for password authentication was removed on August 13, 2021. – Ishita Sinha Jul 27 '23 at 13:37
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"

- 8,131
- 2
- 31
- 30
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.

- 2,140
- 1
- 11
- 17
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.
For Windows Users find the key chain by following:
Control Panel >> User Account >> Credential Manager >> Windows Credential >> Generic Credential

- 1,642
- 1
- 19
- 22

- 151
- 1
- 3
-
2Thank you. This one solved the issue. I couldn't find where it was coming from. – Razi Kallayi Jun 29 '19 at 20:49
-
Yea, i tried most of the solutions but only the going thru the credential manager solved – MonneratRJ Feb 22 '21 at 16:09
-
thank you bro ,This one solved the issue. I couldn't find where it was coming from. – Abdelrahman Mohamed Elakliby Dec 08 '22 at 19:49
From your terminal do:
git config credential.username "prefered username"
OR
git config --global user.name "Firstname Lastname"

- 358
- 3
- 6
**Check by executing this**
git config --list
**Change user email**
git config --global user.email "email@example.com"
**Change user name**
git config --global user.name "user"
**Change user credential name**
git config --global credential.username "new_username"
**After this a window popup asking password.
Enter password and proceed.**

- 797
- 9
- 17
Firstly you need to change credentials from your local machine
- remove generic credentials if there is any
- 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"
- now upload or update your repo it will ask your username and password to get access to github

- 3
- 2

- 7,001
- 45
- 38
For the 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

- 10,143
- 2
- 44
- 50
- 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

- 1,316
- 2
- 13
- 22
I myself have recently faced the same problem. In my case I had two github accounts: work and personal. I wanted to push my starter code to the repository in my personal account but the global configuration had my work account. I didn't want to bother with reconfiguring the global every single time I had to switch between work and personal projects. So I used these commands to set my username and email for that specific personal project folder.
The solution:
$ git config user.name "Alex"
$ git config user.email "Alex@example.com"
$ git config credential.username "your_account_name_here"

- 30,962
- 25
- 85
- 135

- 123
- 1
- 8
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

- 4,315
- 1
- 28
- 19
In linux (Ubuntu 18.04) the username / password are saved as cleartext in the file ~/.git-credentials
, just edit the file to use your new username / password.
The file format is quiet easy, each line contains credentials for one user / domain, in the following format:
https://<username>:<password>@github.com
https://<username2>:<password2>@bitbucket.com
...

- 5,756
- 3
- 39
- 36
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.

- 7,997
- 10
- 40
- 77

- 31
- 5
If you have cloned your repo using url that contains your username, then you should also change remote.origin.url
property because otherwise it keeps asking password for the old username.
example:
remote.origin.url=https://<old_uname>@<repo_url>
should change to
remote.origin.url=https://<new_uname>@<repo_url>

- 466
- 4
- 6