Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure multiple git accounts in Visual Studio Code workspace

When switching between code-bases stored in different git repositories from different servers (for example Bitbucket and Github), I have sometimes committed code using the wrong user name.

Using Visual Studio Code, is there a way to set the values for user.name which are saved for a folder or workspace?

like image 707
H.Scheidl Avatar asked Mar 13 '19 11:03

H.Scheidl


1 Answers

Here are some ways to achieve your result.

Git local config files

Open a terminal in the repo folder and use the commands:

  • git config --local user.name "FIRST_NAME LAST_NAME"
  • git config --local user.email "[email protected]"

Your new configs will appear in the file <REPO_FOLDER>/.git/config.

Now VSCode will override your global settings with the local ones.

Source: https://git-scm.com/docs/git-config

VSCode extensions

Otherways, if you want to directly modify the profile from inside VSCode these are 2 extensions which may help you:

  • https://marketplace.visualstudio.com/items?itemName=onlyutkarsh.git-config-user-profiles
  • https://marketplace.visualstudio.com/items?itemName=stephtr.git-identity

Scheduling idea

Another idea could be running a script from taskschd.msc every X time which checks all folders inside /Github or /Gitlab and assigns the relative profile to the config file.

like image 167
alb_pasqua Avatar answered Oct 20 '22 20:10

alb_pasqua