Changing the Git user inside Visual Studio Code

GitVisual Studio-Code

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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

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

Solution 2 - Git

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.

Solution 3 - Git

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.

Solution 4 - Git

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 [email protected]
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.

Solution 5 - Git

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

Solution 6 - Git

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 git@github.com:newUserName/RepoName.git

Solution 7 - Git

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

Solution 8 - Git

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.

Solution 9 - Git

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.

Solution 10 - Git

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.

Solution 11 - Git

From the Visual Studio Code Command Palette, select:

> GitHub Pull Requests: Sign out of GitHub.

Then sign in with your new credentials.

Solution 12 - Git

Firstly set VS code to default editor through git like

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

After setting vs code to default editor , then type

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

Hope i solve your problem.

Solution 13 - Git

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

Solution 14 - Git

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.

Solution 15 - Git

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

Solution 16 - Git

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!

Solution 17 - Git

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.

.git/config

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

[user]
  name = bar
  email = [email protected]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionapxpView Question on Stackoverflow
Solution 1 - GitGregory ThomasView Answer on Stackoverflow
Solution 2 - GitRamView Answer on Stackoverflow
Solution 3 - GitMohsin MahmoodView Answer on Stackoverflow
Solution 4 - GitYousha Bin ArifView Answer on Stackoverflow
Solution 5 - GitHassan SaeedView Answer on Stackoverflow
Solution 6 - GitPulkitView Answer on Stackoverflow
Solution 7 - GitdiogoView Answer on Stackoverflow
Solution 8 - GitDarpanView Answer on Stackoverflow
Solution 9 - GitMetin YavuzView Answer on Stackoverflow
Solution 10 - GitsrwriterView Answer on Stackoverflow
Solution 11 - GitMohamed GhoubaliView Answer on Stackoverflow
Solution 12 - GitAmer Ahmed ShareefView Answer on Stackoverflow
Solution 13 - Gitsmoore4View Answer on Stackoverflow
Solution 14 - GitsupiView Answer on Stackoverflow
Solution 15 - GitdsugasaView Answer on Stackoverflow
Solution 16 - GitRonaldBView Answer on Stackoverflow
Solution 17 - Gitdrake7View Answer on Stackoverflow