Introduction
This article will be a quick tips if you’re using multiple git config inside one local machine. For example if you’re working on both Gitlab/Bitbucket/Github with different email/username/gpgsign, or you’re working on your personal and work git account on the same machine.
Setup Gitconfig Directory
This directory name would be anything, but for the sake of naming convention let’s call it ~/.gitconfig.d/
.
|
|
Setup Each Gitconfig
Now you have create the directory, let’s say you want to set your personal
and work
account:
Setup Personal Gitconfig
|
|
By using --file=personal
flag, the gitconfig will be configured inside personal
file.
|
|
Now let’s do the same with your work account.
Setup Work Gitconfig
|
|
Now you have set both your account. Then, how to switch between each gitconfig?
Let’s say you put all your company’s git directory at ~/Works
and yours at ~/Personals
. You can switch easily by configure the global gitconfig using includeIf
.
|
|
Conclusion
Now everytime you’re inside ~/Works/
you are using the ~/.gitconfig.d/work
, and when you’re inside ~/Personals/
you are using the ~/.gitconfig.d/personal
.
You can check whether the gitconfig load properly or not by simply executing git config user.email
command and see what email is showing up.
Thank you for reading!