170

The user for my Git commits has changed, but I am not able to change that inside of Visual Studio Code.

I changed the global settings in Git, but when I want to push or sync via Visual Studio Code inside my new repositories I get the error that the oldusername has not the permission to push into newrepository.

At this point it is not the permission. The change of the username did not work for Visual Studio Code. When I use the terminal I can push. It is also not a solution to allow the olduser to push to the newrepository.

I am on Windows 10. So all other tools are working, but just at Visual Studio Code I was not able to change the user.

How can I fix this problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
apxp
  • 5,240
  • 4
  • 23
  • 43
  • 1
    I solved this issue by following the highest rated answer here: https://stackoverflow.com/questions/28238037/git-log-out-user-from-command-line?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Janac Meena Apr 12 '18 at 21:26
  • 1
    I also had this problem after updating git on windows. Took me a while to figure out that the wrong user email was used *only* when using commit from the VSC UI. Using command line, everything was fine. Playing with the credential helper and restarting VSC helped. – Daniel Oct 30 '18 at 17:07
  • Darpans method worked ! after credential manager you have to open the windows credential (click the icon) . then a panel will appear below to show all credentials , if some wrong credentials spotted , then you can click edit icon and enter needful . cheers ! – Indika_Nuwan95 Aug 22 '21 at 16:18
  • In case you need to change Git user to work with different repositories from different accounts or organizations, its far better to change just the local settings in order to publish commits with different users per repository as mentioned [here](https://crunchify.com/how-to-set-github-user-name-and-user-email-per-repository-different-config-for-different-repository/)! – Elias Apr 28 '22 at 09:19

21 Answers21

132

I resolved this issue by setting an email address in Git:

git config --global user.email "email@example.com"
iBug
  • 35,554
  • 7
  • 89
  • 134
Gregory Thomas
  • 1,337
  • 1
  • 7
  • 3
  • 1
    You can set it directly in VSCode Terminal. In Windows have the git command in your path. – Timo Oct 08 '20 at 05:02
54

1. Sign out of your current account (only if you want to switch the current account)

Enter image description here

2. Change Git settings globally

Enter image description here

git config --global user.email youshaarif13@gmail.com
git config --global user.name YushaBinArif3

After completing the above steps, close and reopen Visual Studio Code. The next time you will execute your Git commands, you will be asked to login via browser, make sure you open that link in a browser where your desired GitHub account is logged in.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yousha Arif
  • 1,188
  • 8
  • 20
  • 5
    Nice find but you don't have to go to source before clicking on the profile icon. – Jean Paul Apr 07 '21 at 11:57
  • 1
    only your this solution worked out for me. Thanks you so much. – GRD Apr 05 '22 at 12:09
  • This should be the best answer. – InfiniteStack Sep 20 '22 at 16:44
  • Best answer! On VS Code, just sign out from the current account. Click "Sign in to sync". A login confirmation page opens in your browser saying that "You're now signed in" – Chima Oct 31 '22 at 16:37
  • Best answer! On VS Code, just sign out from the current account. Click "Sign in to sync". A login confirmation page opens in your browser saying that "You're now signed in" – Chima Oct 31 '22 at 16:37
52

Generally, Visual Studio Code uses the GitHub credentials from the system's credential manager. It doesn't store it anywhere in the settings. As question says, Changing the Git user inside Visual Studio Code, is not inside rather outside.

Search for or go to Credential Manager (Windows control panel) → Windows Credentials → update the GitHub password from the list.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ram
  • 1,461
  • 1
  • 13
  • 17
  • 3
    The real problem solved by going in Windows control panel) -> Windows Credentials -> Update – Nirmalya Kar Apr 16 '20 at 19:47
  • 3
    In the german windows 10 version, it should be here: `Systemsteuerung\Benutzerkonten\Anmeldeinformationsverwaltung`. The username in my case is `personalaccesstoken`. It is in the category `generic credential information`. – Timo Oct 08 '20 at 04:57
  • 6
    @darkKnight On the Mac, this worked for me : open the Keychain app, look for an entry called vscodevscode.github-authentication (of type "application password") and remove it. Reauthenticate from Github, which will open your browser and re-ask for your (other) username – altius_rup Jan 29 '21 at 14:56
  • Why are not you at the top? This is the real issue and I managed to fix by simply deleting the Windows github credentials and VS Code sign me up again with the correct once. I spent one day trying to do that and messing with VS Code while the solution was so simple. Thank you so much! – gargara123456 Jan 20 '22 at 03:15
  • https://cmatskas.com/how-to-update-your-git-credentials-on-windows/ – omercotkd Mar 21 '22 at 12:03
31

To check/get old values:

git config --global user.email
git config --global user.name

Output:

youold@email.com
youroldgoodname

To set new values

git config --global user.email yournew@email.com
git config --global user.name yournewgoodname
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hassan Saeed
  • 6,326
  • 1
  • 39
  • 37
30

You can view all of your settings and where they are coming from using:

git config --list --show-origin

Delete the unwanted credentials from the directory and then Visual Studio Code will ask you for the credentials next time when you perform Git operation.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mohsin Mahmood
  • 3,238
  • 3
  • 21
  • 25
  • 2
    This is the easiest and the best way to update the git user name and password. Note: once you enter the above command open the file with old username in editor and update the username with the new username and save the file. now when you issue git command as sync or pull it will ask for credential to enter. use the current new user credential and it works like charm. – Joshua I Jun 22 '20 at 14:34
  • 2
    This opens the editor "vim" and you can close it by typing "q" and clicking Enter in Windows. – Erik Dec 13 '21 at 09:54
22

Here are 2 simple solutions:

  1. Git Graph

    You can change the git user in the Extension Git Graph easily.

    1. Go to the Extensions tab and install Git Graph.
    2. Go to the Source Control tab in the SOURCE CONTROL accordion menu.
    3. Click on the View Git Graph (git log) icon. Git Graph - Repository Settings
    4. Click on the Repository Settings icon.
    5. In the User Details section, click Edit and change the Git User Name and Email.
  2. .git/config

    A simpler solution that works with any IDE is to add the user to the .git/config file in your current project:

    git remote repository test/
    ├─ .git/
    │  ├─ config
    ├─ hello_world.md
    

    In the .git/config file, change or add this text:

    [user]
      name = bar
      email = bar@mail.com
    
drake7
  • 952
  • 7
  • 20
  • 1
    does not work. 1) View Git Graph not found in accordion menu. 2) user.name is ignored for authentication – Kux Oct 22 '22 at 17:26
  • @Kux - read the first step again. It says, "Go to the Extensions tab and install Git Graph". Then you'll see the Git Graph icon in accordion menu. – Yash Gupta Feb 21 '23 at 14:47
  • You're my hero, was having huge trouble, I guess it was related to having my default terminal set to msys – Amfasis Mar 29 '23 at 08:51
  • the second solution worked flawlessly. If anyone is having a tough time finding this file, use control + P on VS code and type .git/config and it will show up – Muhammad Mubashirullah Durrani Jul 30 '23 at 15:48
16

I had the same problem as Daniel. Setting the commit address and unsetting the credentials helper also worked for me.

git config --global user.email '<git-commit-address>'
git config --global --unset credential.helper
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
diogo
  • 525
  • 1
  • 7
  • 12
13

Press Ctrl + Shift + G in Visual Studio Code and go to more and select Show git output. Click Terminal and type git remote -v and verify that the origin branch has latest username in it like:

origin git@github.com:DroidPulkit/Facebook-Chat-Bot.git (fetch)

origin git@github.com:DroidPulkit/Facebook-Chat-Bot.git (push)

Here DroidPulkit is my username.

If the username is not what you wanted it to be then change it with:

git add remote origin git@github.com:newUserName/RepoName.git
Pulkit
  • 1,020
  • 3
  • 12
  • 26
  • 2
    Here `DroidPulkit` is the username of GitHub Account. But repo `Push/Pull` user/email can be different that is set by `git config user.name ...`, `git config user.email ...`. – Sajib Khan Feb 18 '17 at 19:14
  • 2
    I am using https but the output is: `origin https://github.com/newUserName/reponame (fetch)` ... I already found something about credential helpers, which is used. Maybe VSC is the only tool using that. But I don't know how to change the user there. – apxp Feb 18 '17 at 19:19
  • 1
    just a reminder can you do this again: git config --global user.name yourname git config --global user.email youremail@address.com and restart VS Code and probably git too – Pulkit Feb 18 '17 at 19:24
  • Thanks for the reminder. Did that more then once. Inside git the settings are ok, it is just VS Code missing. – apxp Feb 18 '17 at 19:28
11

This could be because of the reason that the credentials are saved and you need to update those credentials and you can do that by following the below steps:

Control panelCredential Manager → under Generic credential, you will be able to see the credentials related to Git.

Try to update them. If that does not work, delete them and add new ones.

For other platforms or different versions of the operating system, you need to find out where the credentials are saved related to Git and update them.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Darpan
  • 234
  • 3
  • 15
4

There is a conflict between Visual Studio 2015 and Visual Studio Code for the Git credentials. When I changed my credentials on Visual Studio 2015, Visual Studio Code let me push with the correct Git ID.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • I found this too. I set the correct email in Visual Studio 2019: Top Menu: Git | Settings | Source Control | Git Global Settings | Email. Once this was done, I didn't need to do anything for Visual Studio 2017 or Visual Studio Code - both had been fixed by the change in VS 2019. Thank you @metin-yavuz – Gail Foad Mar 11 '21 at 11:01
3

Firstly set VS code to default editor through git like

git config --global core.editor "code --wait"
git config --global -e 

After setting vs code to default editor , then type

git config --global --list 

it will show you all global configuration

If you want to change any just type

git config --global -e

Vs code will open then change your user.name , email-address & any thing you set in easy manner.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
3

The quick and easy way is to sign in at https://github.com as the user you want to use, then in the lower left corner, sign-in to Github (sign off if any user is currently connected). VS Code will use the user that you are already logged in as in the browser.

enter image description here

smoore4
  • 4,520
  • 3
  • 36
  • 55
3

HAVE AS MANY ACCOUNTS AS YOU WANT JUST SET THE CONFIG FOR THAT PROJECT

NO MORE SIGNIN AND SIGNOUT!

So there is an extension with a name git-autoconfig by shyykoserhiy.

After installing it open the command palette ctrl + shift + p. Type git-autoconfig and it will have 2 options one being set-Config and other get-Config and these both serve the same purpose which their name is conveying.

Every time you open the project in vscode it will prompt you automatically which config to use (in case of multiple accounts).

It is as easy as setting it with git-setconfig

Wahab Shah
  • 2,066
  • 1
  • 14
  • 19
2

I just signed up for a new GitHub account to create a project and I had the same issue. I resolved it by doing the following:

$ git credential-osxkeychain erase
host=github.com
protocol=https
> [Press Return]

When I attempted to push to my new remote repo after this, it asked me to sign in to the new account; I did that, and it worked.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
srwriter
  • 31
  • 3
2

if you are using Mac System,

open keychain -> search for 'github' -> delete "github.com / internet password" file -> now add new user through terminal or git bash.

in somecases you can try this in vs code, check the left bottom section with profile icon, if you have git account signed in and listed here, right click on the account name and signout. reload vs code and try to sign again with new account.

To check current credentials:

git config --global user.name
git config --global user.email

To set global level credentials:

git config --global user.name
git config --global user.email

To set repo level credentials:

git config user.name
git config user.email

i was facing same issue, as i was working with 2 different account. the above first solution worked for me, as i was having mac system.

1

From the Visual Studio Code Command Palette, select:

GitHub Pull Requests: Sign out of GitHub.

Then sign in with your new credentials.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

if you use mac system you need open terminal in pc, not in vs code

zekoliman
  • 113
  • 1
  • 6
0

From within the Visual Studio Code terminal,

git remote set-url origin https://<your github username>:<your password>@github.com/<your github username>/<your github repository name>.git

for the quickest, but not so encouraged way.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
supi
  • 2,172
  • 18
  • 15
  • would this add the remote url only for that folder/project or globally? – vikrant Feb 10 '21 at 07:34
  • not globally, rather more for the current session – supi Feb 18 '21 at 06:23
  • Why is it not an encouraged way? Can you elaborate a little bit? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/65701333/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Nov 17 '21 at 23:10
  • @PeterMortensen I guess because the password is in plaintext? – Ian Grainger Jun 02 '22 at 09:06
0

I was running into this because I had incorrectly typed my GitHub/GitLab credentials into the pop-up from Windows Credentials Manager. In Windows 10, access Credential Manager from Control Panel; you can also just search for Credential Manager in the search bar. In Credential Manager, find your Git credentials in Windows Credentials and amend to the correct version. After this, Git worked from the CLI.

Others have made suggestions about trying to trigger the pop-up again by signing out of GitHub and running git pull from the CLI, but neither of those worked for me.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dsugasa
  • 663
  • 1
  • 9
  • 26
0

I tried several changes to settings, including the Windows Credential manager. In the end, I:

  1. Closed Visual Studio Code
  2. Opened PowerShell
  3. Set the credentials there, with the --global option
  4. Closed PowerShell
  5. Opened Visual Studio Code

Visual Studio Code is now happy with its Git name and email, and I'm able to push and pull!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RonaldB
  • 1,110
  • 1
  • 10
  • 19
0

In my case it didn't work until it dawned on me that I was using vscode for WSL. It turned out that in this case it is necessary to specify credentials in WSL. If you are also using WSL, just open a WSL terminal and use these commands. (I haven't checked, but it's likely the same applies to SSH).

Smok1e
  • 51
  • 1
  • 3