This guide will help git to automatically use work email for any repo in work folder, and personal email for any repo in github folder.
Edit ~/.gitconfig by text editor or just vi ~/.gitconfig if you know how to use vim.
- Add these lines:
[includeIf "gitdir/i:github/"]
path = .gitconfig-github
[includeIf "gitdir/i:work/"]
path = .gitconfig-work'
- Remove email key in
[user]section.
Optional:
- Remove name key, if you want to config your name differently.
- Remove
/ito make it case sensitive. Example:[includeIf "gitdir:github/"]
Create a file at ~/.gitconfig-github: touch ~/.gitconfig-github.
Edit the file: vi ~/.gitconfig-github
[user]
email = [email protected]
name = John Smith
Remove the name key if you already set it up in global config.
Do the same for work config file ~/.gitconfig-work.
Now all repo under folder work will use work email, all repo under folder github will use personal email.