The question about how to use multiple identities for Git has already been asked several times... I read some instructions and followed this one
https://itnext.io/setup-git-with-multiple-configs-9b4111d6928c
At home I'm using Linux and Github. At work I'm using Windows 10 and Gitlab. Two Git identities are required for work.
I changed the .gitconfig located at
C:\Users\jdoe
from
[user]
name = johndoe
email = johndoe@gmail.com
[credential]
helper = store
[winUpdater]
recentlySeenVersion = 2.24.1.windows.2
[core]
editor = \"C:\\Users\\jdoe\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" --wait
to
[includeIf "gitdir:~/Desktop/Repositories/Gitlab/"]
path = ~/Desktop/Repositories/Gitlab/.gitconfig
[includeIf "gitdir:~/Desktop/Repositories/Github/"]
path = ~/Desktop/Repositories/Github/.gitconfig
[credential]
helper = store
[winUpdater]
recentlySeenVersion = 2.24.1.windows.2
[core]
editor = \"C:\\Users\\jdoe\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" --wait
Next I created a directory Gitlab at
C:\Users\jdoe\Desktop\Repositories\Gitlab
and a directory Github at
C:\Users\jdoe\Desktop\Repositories\Github
Within both directories I created a .gitconfig. For Gitlab I use my Gitlab credentials (work account)
[user]
name = jdoe
email = john.doe@company.com
For Github I use my private account credentials
[user]
name = johndoe
email = johndoe@gmail.com
I tested both platforms with demo repositories. When committing both platforms receive a commit from an unknown nonexisting user with the username
Doe
I don't know where this username comes from. I would expect Gitlab showing the username jdoe and Github showing the username johndoe.
I also tried to remove all generic credentials with this guide
https://stackoverflow.com/a/41968176/9945420
After doing so I was prompted for the Github credentials. Unfortunately Github and Gitlab still receive commits from a nonexisting user called Doe.
Any help would be appreciated
Update:
I tested this way on my private Linux machine and it worked. But for my Windows 10 work machine it didn't.
Second update:
I tested this without using VS Code. When committing via terminal it also works on my Windows 10 machine...
When I open a terminal window within VS Code, modify a file and run
$ git add .
$ git commit -m "test"
$ git push
it commits correctly. When I commit via VS Code Git integration and run
$ git push
later on, it commits with a non existing user.