I need to do dev of work on my personal laptop. Usually, I will clone the repository and set a work email for that repository by git config user.email <your@email.com>
. That requests config for each working repositories, and if there are other settings, it requires more actions. And most important, I forget to set up it sometimes.
Later, I did search on the internet and found I am actually able to set a separated gitconfig for the specific folder. Below are the steps.
~/.gitconfig-work
git config -f ~/.gitconfig-work user.email <your@email.com>
Now we have gitconfig file for working.
git config --global include.path "~/.gitconfig-work"
git config --global "includeIf.gitdir:~/work/.path" "~/.gitconfig-work"
Then for all repositories inside of work folder, it will use the new config file.
Add isWork
to the new config file
git config -f ~/.gitconfig-work core.isWork true
And run below command inside of the work folder to see if the config is applied
git config --get core.isWork || echo false
credit/reference: [https://filipe.kiss.ink/multiple-gpg-keys-git/]