Changing the Git user inside Visual Studio Code
Asked Answered
D

25

203

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?

Dorm answered 18/2, 2017 at 17:55 Comment(4)
I solved this issue by following the highest rated answer here: #28238537Jaquiss
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.Mahayana
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 !Circumfluent
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!Leandro
O
145

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

git config --global user.email "[email protected]"
Oldham answered 8/12, 2018 at 8:24 Comment(3)
You can set it directly in VSCode Terminal. In Windows have the git command in your path.Impossible
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?Slapbang
For me after that command i had to restart vs code in order for that change to take effectPuzzle
C
72

Here are some steps to address this issue.

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

The commands are

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.

Concinnous answered 5/4, 2021 at 7:6 Comment(3)
Nice find but you don't have to go to source before clicking on the profile icon.Upward
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"Mete
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"Mete
N
56

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.

Nitro answered 22/1, 2020 at 6:31 Comment(5)
The real problem solved by going in Windows control panel) -> Windows Credentials -> UpdateSaddlery
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.Impossible
@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) usernameNoreennorene
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!Ramsey
cmatskas.com/how-to-update-your-git-credentials-on-windowsSuppose
L
37

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
Leafage answered 10/5, 2021 at 13:8 Comment(0)
E
29

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.

Enstatite answered 4/5, 2020 at 11:35 Comment(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.Naranjo
This opens the editor "vim" and you can close it by typing "q" and clicking Enter in Windows.Sickle
W
29

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]
    
Wolbrom answered 26/4, 2022 at 16:56 Comment(4)
does not work. 1) View Git Graph not found in accordion menu. 2) user.name is ignored for authenticationStalingrad
@Stalingrad - 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.Bomar
You're my hero, was having huge trouble, I guess it was related to having my default terminal set to msysEugenioeugenius
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 upSuperior
M
18

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
Minnesinger answered 5/12, 2019 at 7:21 Comment(0)
I
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
Improbity answered 18/2, 2017 at 19:9 Comment(4)
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 ....Acaudal
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.Dorm
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 tooImprobity
Thanks for the reminder. Did that more then once. Inside git the settings are ok, it is just VS Code missing.Dorm
C
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.

Clarino answered 3/5, 2020 at 20:19 Comment(0)
R
5

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

Rolypoly answered 14/3, 2022 at 13:40 Comment(4)
worked for me after trying most other suggestions hereShew
I don't get the option to login in this menu. I just get the sentence "You are not signed in to any accounts"Sanches
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.Macedonian
This truly was the easiest way. Thanks a ton !!Cosmetic
B
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.

Banister answered 11/11, 2018 at 8:19 Comment(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-yavuzRawinsonde
S
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.

Smew answered 15/2, 2022 at 4:19 Comment(0)
A
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

Afterburner answered 22/6, 2022 at 12:55 Comment(0)
B
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.

Bradawl answered 11/3, 2021 at 12:4 Comment(0)
A
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.

Azobenzene answered 11/11, 2022 at 6:59 Comment(0)
L
1

From the Visual Studio Code Command Palette, select:

GitHub Pull Requests: Sign out of GitHub.

Then sign in with your new credentials.

Loginov answered 3/9, 2019 at 12:0 Comment(0)
P
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.

Pile answered 13/1, 2021 at 11:45 Comment(4)
would this add the remote url only for that folder/project or globally?Lakenyalaker
not globally, rather more for the current sessionPile
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).Depolarize
@PeterMortensen I guess because the password is in plaintext?Algerian
N
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

Nedneda answered 16/7, 2021 at 7:50 Comment(0)
M
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!

Monostich answered 16/11, 2021 at 16:52 Comment(0)
D
0

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

Decern answered 9/6, 2022 at 12:37 Comment(0)
C
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).

Clower answered 2/3, 2023 at 23:14 Comment(0)
C
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.

Choleric answered 6/9, 2023 at 13:22 Comment(0)
O
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]>"
Omnivorous answered 8/12, 2023 at 16:6 Comment(0)
C
0

if your VS code do have multiple users signed in atm, and you want to make sure the current commit will be made with one of them, just do the following will work

git config user.email "[email protected]"

if you have multiple VS code windows open. you could check the current git user in terminal by typing in

git config user.email

if the output email is not your expected one, just repeat the previous command.

personally, I prefer not doing --global with git configuration, because if you have multiple users signed in in git, that probably means you need them both to do different stuff.

Cockcrow answered 31/12, 2023 at 0:25 Comment(0)
C
0

To change github accounts in vscode quickly using your CLI you can:

  1. Disable user settings => git authentication in your vscode config

  2. Update or install gh cli to the last version

If using MacOs you can use: brew upgrade gh or brew install gh And then use:

  1. Set up gh cli as your credentials manager:

gh auth setup-git

  1. Login with the accounts you need:

gh auth login

  1. Change between your github accounts using

gh switch

You can also use gh auth switch -u <username> too

Hope it helps!

Edit: I also created some aliases in my ~/.zshrc

alias authghftg='gh auth login --with-token < ~/ftg_gh.txt && gh auth status;'
alias authghjdr='gh auth login --with-token < ~/jdr_gh.txt && gh auth status;'  

alias ghftg='gh auth switch -u JesusFTG;'
alias ghjdr='gh auth switch -u JesusDR01;'

So I can just use authghjdr and authghftg and then ghftg or ghjdr to switch between my github accounts and perform my pulls, clones and commits.

Criticism answered 28/2 at 12:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.