Like most devs, I use Git both for personal and work stuff, but I need to use distinct user details in each case to sign-off my commits. I have a global .gitconfig that define my personal email as user.email, but whenever I need to pull a new work project, I have to remember to set it to a different value locally. Which I keep forgetting to do.
So I have found a way to alter my git config based on the directory I am working from. All you need to do is add these lines to your ~/.gitconfig:
[user]
name = My Name
email = personal@email.com
# Use work email for repositories under ~/dev/work
[includeIf "gitdir:~/dev/work/"]
path = ~/.gitconfig-workAnd edit .gitconfig-work:
[user]
email = work-email@mycompany.comI think this also applies to other git config values, so feel free to experiment!
