181

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?

4
  • 1
    I solved this issue by following the highest rated answer here: stackoverflow.com/questions/28238037/… Apr 12, 2018 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, 2018 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 ! Aug 22, 2021 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!
    – Elias
    Apr 28, 2022 at 9:19

23 Answers 23

139

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

git config --global user.email "[email protected]"
2
  • 1
    You can set it directly in VSCode Terminal. In Windows have the git command in your path.
    – Timo
    Oct 8, 2020 at 5:02
  • I noticed I had multiple [user] sections in .gitconfig and VCode picked wrong user to commit on remote Azure Devops Repo. Is there way to control this without deleting other entries?
    – RSW
    Sep 21 at 10:56
59

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 y*********@gmail.com
git config --global user.name Y*********

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.

3
  • 7
    Nice find but you don't have to go to source before clicking on the profile icon.
    – Jean Paul
    Apr 7, 2021 at 11:57
  • 1
    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, 2022 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, 2022 at 16:37
53

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.

5
  • 3
    The real problem solved by going in Windows control panel) -> Windows Credentials -> Update Apr 16, 2020 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 8, 2020 at 4: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, 2021 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! Jan 20, 2022 at 3:15
35

To check/get old values:

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

Output:

[email protected]
youroldgoodname

To set new values

git config --global user.email [email protected]
git config --global user.name yournewgoodname
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.

2
  • 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, 2020 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, 2021 at 9:54
25

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 = [email protected]
    
4
  • 1
    does not work. 1) View Git Graph not found in accordion menu. 2) user.name is ignored for authentication
    – Kux
    Oct 22, 2022 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 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 at 8: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 Jul 30 at 15:48
17

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
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 [email protected]:DroidPulkit/Facebook-Chat-Bot.git (fetch)

origin [email protected]: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 [email protected]:newUserName/RepoName.git
4
  • 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, 2017 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, 2017 at 19:19
  • 1
    just a reminder can you do this again: git config --global user.name yourname git config --global user.email [email protected] and restart VS Code and probably git too
    – Pulkit
    Feb 18, 2017 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, 2017 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.

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.

1
  • 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, 2021 at 11:01
4

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

3
  • worked for me after trying most other suggestions here
    – wlf
    Apr 28, 2022 at 5:20
  • I don't get the option to login in this menu. I just get the sentence "You are not signed in to any accounts"
    – marts
    Nov 19, 2022 at 19:29
  • Thant probably means that you have no extension installed or activated that requires some kind of login. As soon as you install/activate such extension this badge will most probably change.
    – myf
    Nov 10 at 13:40
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

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.

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.

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.

1

From the Visual Studio Code Command Palette, select:

GitHub Pull Requests: Sign out of GitHub.

Then sign in with your new credentials.

1

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

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.

4
  • would this add the remote url only for that folder/project or globally?
    – vikrant
    Feb 10, 2021 at 7:34
  • not globally, rather more for the current session
    – supi
    Feb 18, 2021 at 6:23
  • Why is it not an encouraged way? Can you elaborate a little bit? Please respond by editing (changing) your answer, not here in comments (without "Edit:", "Update:", or similar - the answer should appear as if it was written today). Nov 17, 2021 at 23:10
  • @PeterMortensen I guess because the password is in plaintext? Jun 2, 2022 at 9: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

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!

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).

0

The answer with most votes did not help me. But I managed to solve it by directly modifying the git config file.

  1. Go to the git config file .git -> config
  2. edit the origin url https://username@<your git url> (i.e, add the username in front of the domain followed by a @)

Hope this helps.

0

In my case, on Windows, setting --global had no effect on VS Code, but looking into git logs, I saw the issue:

to set your account's default identity.
Omit --global to set the identity only in this repository.

So SOLUTION is simply do:

git config user.name "my_user"    
git config user.email "[email protected]>"

Not the answer you're looking for? Browse other questions tagged or ask your own question.