Git config with Multiple Email Addresses
I am working on open source project and my company project. So I need to have multiple email for git commits. If I start working on my company project, I have to change my git config email by running git config --global user.email work@domail.com
. On the other hand, if I start working on open source project, I have to run git config --global user.email personal@email.com
.
Sometime I forgot to follow the above step for git configuration, and this create problem for me. In following steps, I am going to explain how to setup git config globally and locally for each project.
In this tutorial I will cover:
- Where the git config located both globally and locally.
- How to config git locally and globally.
1- Set Git config Globally
Run
git config --global user.name "Your Name"git config --global user.email "Your Email"
It will save the config in to $home/.gitconfig
file.
Note : By default, all project gets the config globally if it had not been setup locally.
2 — Set Git Config Locally
By default, all project get the config from global config file which is in above image, but it can be set it locally. To setup locally run the following commend.
git config user.name "Your Name"git config user.email "Your Email"
It will save the config in to .git/config
file of the project.
Bonus:
Git configuration can be added in system level as well which can be used for all other users.
:) Thanks for the reading and Happy coding.