apxp
apxp

Reputation: 5884

Changing the Git user inside Visual Studio Code

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?

Upvotes: 226

Views: 880835

Answers (26)

Swapnil Pathare
Swapnil Pathare

Reputation: 69

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 <name>  
git config --global user.email <your-email>

To set repo level credentials:

git config user.name <name>  
git config user.email <your-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.

Upvotes: 3

Wenuka
Wenuka

Reputation: 1082

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

Upvotes: 4

bules2
bules2

Reputation: 11

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

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.

Upvotes: 0

Charles Brocchiero
Charles Brocchiero

Reputation: 303

On my end, I had to change that setting in VS Code. It works now! enter image description here

Upvotes: 4

Yousha Arif
Yousha Arif

Reputation: 1588

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.

Upvotes: 93

peiting sun
peiting sun

Reputation: 53

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.

Upvotes: 0

697
697

Reputation: 621

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]>"

Upvotes: 0

drake7
drake7

Reputation: 1214

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]
    

Upvotes: 36

srwriter
srwriter

Reputation: 41

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.

Upvotes: 3

Amer Ahmed Shareef
Amer Ahmed Shareef

Reputation: 41

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.

Upvotes: 4

Smok1e
Smok1e

Reputation: 61

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

Upvotes: 0

Wahab Shah
Wahab Shah

Reputation: 2256

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

Upvotes: 4

zekoliman
zekoliman

Reputation: 105

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

Upvotes: -2

smoore4
smoore4

Reputation: 4866

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

Upvotes: 10

RonaldB
RonaldB

Reputation: 1190

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!

Upvotes: 0

Hassan Saeed
Hassan Saeed

Reputation: 7080

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

Upvotes: 42

Mohsin Mahmood
Mohsin Mahmood

Reputation: 3436

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.

Upvotes: 30

Darpan
Darpan

Reputation: 244

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.

Upvotes: 12

Ram
Ram

Reputation: 1591

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.

Upvotes: 60

diogo
diogo

Reputation: 771

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

Upvotes: 21

Mohamed Ghoubali
Mohamed Ghoubali

Reputation: 21

From the Visual Studio Code Command Palette, select:

GitHub Pull Requests: Sign out of GitHub.

Then sign in with your new credentials.

Upvotes: 2

dsugasa
dsugasa

Reputation: 683

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

Upvotes: 0

supi
supi

Reputation: 2272

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.

Upvotes: 0

Metin Yavuz
Metin Yavuz

Reputation: 51

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.

Upvotes: 5

Gregory Thomas
Gregory Thomas

Reputation: 1597

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

git config --global user.email "[email protected]"

Upvotes: 158

Pulkit
Pulkit

Reputation: 1040

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

Upvotes: 14

Related Questions