Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Change GitHub users in Visual Studio Code 👥

Here is a script that allows you to change GitHub users in Visual Studio Code.

#!/usr/bin/env python3

import subprocess

def change_github_user(user, mail):
  """Changes the GitHub user in Visual Studio Code.

  Args:
    user: The GitHub user name.
    mail: The Github user mail. 
  """

  # Set the global Git user name.
  subprocess.run(["git", "config", "--global", "user.name", user])

  # Set the global Git email address.
  subprocess.run(["git", "config", "--global", "user.email", mail])

  # Restart Visual Studio Code.
  subprocess.run(["code", "--restart"])

# Get the new GitHub user name from the user.
user = input("Enter the new GitHub user name: ")

# Get the new GitHub mail from the user.
mail = input("Enter the new GitHub user mail: ")

# Change the GitHub user in Visual Studio Code.
change_github_user(user, mail)

To use this script, save it as a Python file (e.g. change_github_user.py), made it executable and run it in a terminal. You will be prompted to enter the new GitHub user name and mail. Once you have entered theuser name and mail, Visual Studio Code will be restarted with the new user settings.

Note that this script will change the global Git user settings. If you are working on multiple projects that use different GitHub accounts, you may want to change the Git user settings on a per-project basis instead. To do this, you can use the git config command in the root directory of each project.

Remember to use an alias to make it more simple and easy to use 💡