I've tried the way @JavIon has provided:
https://medium.com/uncaught-exception/setting-up-multiple-gitlab-accounts-82b70e88c437
On my system, I've done some fine tuning.
1st step:
Go into your local directories where you use Git. In my case, I use Git with GitLab.
In my work directory are some git repositories and some regular files and directories - same in my private directory.
I've created in each of these directories a .gitignore file.
Work:
#------------------------------------------#
# .gitconfig GitLab Work #
#------------------------------------------#
[user]
name = My name for commits at work
email = [email protected]
username = Work GitLab username
Private:
#------------------------------------------#
# .gitconfig GitLab Private #
#------------------------------------------#
[user]
name = My name for commits at private
email = [email protected]
username = Private GitLab username
2nd step:
Go into your home directory and open .gitconfig (if there is none, create one).
Then include the .gitconfig files from your directories, except that in home directory.
~/.gitconfig:
#-----------------------------------#
# .gitconfig Global #
#-----------------------------------#
#----------------- Work GitLab
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig
#----------------- Private GitLab
[includeIf "gitdir:/~/private/"]
path = ~/private/.gitconfig
3rd step:
Go into your local Git repositories and add in all of them the specific SSH key.
ssh-add ~/.ssh/<your key>
For me, that has worked without logout or reboot.