Last updated: Apr 5, 2024
Reading time·4 min
To change the Git user in Visual Studio Code:
Ctrl
+ Shift
+ P
on Windows and LinuxCommand
+ Shift
+ P
on macOSF1
to open the Command Palette.You can also open the terminal by using a keyboard shortcut:
Ctrl
+ ` (backtick).Ctrl
+ ` (backtick).Once you open the terminal, run the following commands.
Make sure to replace the placeholders with your actual git username and email.
git config --global user.name "your_username" git config --global user.email "your_email@example.com"
You can run the git config --list
command to verify the git account has been
switched.
git config --list
You can view where each setting is set by issuing the following command.
git config --list --show-origin
The --show-origin
option will display the file that contains each setting.
You can manually update the entries in the file if you see any inconsistencies.
On Windows, you might encounter issues because VS Code takes the GitHub credentials from Windows Credentials Manager.
You can also delete the GitHub entry under Generic Credentials and reauthenticate with GitHub with the correct username and password.
You can also run the git push
command to get prompted for your new credentials
after deleting the current entry.
On macOS, you might have to delete your old GitHub credentials from Keychain Access if they shadow your new credentials.
If you need to change the active GitHub account:
If the Accounts icon is not displayed in the Activity Bar, right-click on the Activity bar (leftmost sidebar) and tick the Accounts menu.
If you also need to change your global git configuration, run the following commands from your terminal.
Make sure to replace the placeholders with your actual git username and email.
git config --global user.name "your_username" git config --global user.email "your_email@example.com"
You can run the git config --list
command to verify the git account has been
switched.
git config --list
You might get automatically signed in with the currently active GitHub account, so make sure to sign in with your preferred GitHub account before clicking on the Sign in to Sync Settings button.
An alternative approach to changing your GitHub account in VS Code is to use the GitHub Pull Requests and Issues extension.
Ctrl
+ Shift
+ X
on Windows or LinuxCommand
+ Shift
+ X
on macOSYou can now use the extension to change your GitHub account in VS Code:
The extension will use the currently logged-in GitHub user from your browser, so make sure to log in with the correct GitHub account.
Click on the Profile icon in the bottom left corner.
If you need to sign out:
I've also written an article on how to undo the last Git commit in VS code.
You can learn more about the related topics by checking out the following tutorials: