Problem
I use my own laptop to code for both personal and work projects. However, I want to use my work email address only for my work projects. But I am lazy to set it for each repository.
Here is my folder structure. All work projects are under the same folder ~/src/work
. Other projects are personal projects.
~/src/work/project-i # work project
~/src/work/project-j # work project
~/src/playground/project-a # personal project
~/src/bots/project-b # personal project
~/src/devops/project-c # personal project
Solution
Step 1. Add an includeIf
section to global git config file ~/.gitconfig
. (Create this file if it does not exist)
[user]
name = Franz
# personal email address
email = franz@whatever.com
[includeIf "gitdir:~/src/work/"]
path = ~/src/work/.gitconfig
Step 2. Add the work email address to our work git config file ~/src/work/.gitconfig
. (Create this file if it does not exist)
[user]
# work email address
email = franz@serious.com
After you have done these steps, when you commit code to your work projects, the email used in commit will be your work email address.
Top comments (0)