Changing the Git user or the GitHub account in VS Code

avatar
Borislav Hadzhiev

Last updated: Apr 5, 2024
4 min

banner

# Changing the Git user in Visual Studio Code

To change the Git user in Visual Studio Code:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux
  • Command + Shift + P on macOS
Note: you can also press F1 to open the Command Palette.
  1. Type toggle terminal and select View: Toggle Terminal.

vscode open terminal

You can also open the terminal by using a keyboard shortcut:

  • on Windows and Linux: Ctrl + ` (backtick).
  • on macOS: Ctrl + ` (backtick).

Once you open the terminal, run the following commands.

Make sure to replace the placeholders with your actual git username and email.

shell
git config --global user.name "your_username" git config --global user.email "your_email@example.com"

change git user in vscode

You can run the git config --list command to verify the git account has been switched.

shell
git config --list

You can view where each setting is set by issuing the following command.

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

# A note on Windows

On Windows, you might encounter issues because VS Code takes the GitHub credentials from Windows Credentials Manager.

  1. Click on the search field, type Control Panel and start the application.

open control panel

  1. Click on User Accounts.

click user accounts

  1. Click on Credential Manager.

click credential manager

  1. Click on Windows Credentials.

click windows credentials

  1. Under Generic Credentials, click on your git credentials and update your GitHub username and password by clicking on the row and selecting Edit.

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.

# A note on macOS

On macOS, you might have to delete your old GitHub credentials from Keychain Access if they shadow your new credentials.

  1. Open the Keychain Access application.
  2. Right-click on System in the left menu and select Unlock Keychain "System".
  3. Type github in the search field at the top.
  4. Select the entries, right-click and delete them.
  5. Push your code to GitHub to get prompted to enter your new credentials.

# Changing the GitHub account in VS Code

If you need to change the active GitHub account:

  1. Click on the profile icon in the bottom left corner.

sign out of current github account

  1. Hover over your Github username.
  2. Click on the Sign Out button.

If the Accounts icon is not displayed in the Activity Bar, right-click on the Activity bar (leftmost sidebar) and tick the Accounts menu.

show accounts menu

  1. Click on the Accounts icon and then select Sign in to Sync Settings.

sign in to sync settings

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.

shell
git config --global user.name "your_username" git config --global user.email "your_email@example.com"

change git user in vscode

You can run the git config --list command to verify the git account has been switched.

shell
git config --list
  1. Then select Sign in with GitHub.

select sign in with github

  1. You will be redirected to your browser where you can sign in with the new GitHub account.

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.

# Using the GitHub Pull Requests extension to change your GitHub account

An alternative approach to changing your GitHub account in VS Code is to use the GitHub Pull Requests and Issues extension.

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux
    • Command + Shift + X on macOS
  1. Type GitHub Pull Requests.

install enable github pull requests extension

  1. Make sure you have the GitHub Pull Requests and Issues extension installed and enabled.

You can now use the extension to change your GitHub account in VS Code:

  1. The extension will use the currently logged-in GitHub user from your browser, so make sure to log in with the correct GitHub account.

  2. Click on the Profile icon in the bottom left corner.

click sign in with github

  1. Select Sign in with GitHub to use GitHub Pull Requests and Issues.

If you need to sign out:

  1. Click on the profile icon in the bottom left corner.

sign out of current github account

  1. Hover over your Github username.
  2. Click on the Sign Out button.

I've also written an article on how to undo the last Git commit in VS code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.