TL;DR: since Git 2.13 there's an easy way to differentiate between personal and work Git credentials. More on that below.
Just like many IT professionals I have a Github account which I use both for my personal and day job projects.
Github allows to setup multiple email addresses in your account and even custom notification routing so that notifications for work repositories go to your work email. Here's a screenshot from notifications settings page:
Since I'm registered in Github using my personal email address (email@example.com) and personal nickname (wheleph), my global
~/.gitconfig is setup accordingly:
# This is Git's per-user configuration file. [user] name = wheleph email = firstname.lastname@example.org
This means that every time I do
git commit this is what other people see:
Author: wheleph <email@example.com>
That's fine for my personal repos but it's not ideal for my work repos. For those repos I'd like to have something like:
Author: Volodymyr Sobotovych <firstname.lastname@example.org>
Of course it's possible to have individual
.git/config for every work repo I have locally. This is tedious and error-prone but for older Git releases it was the only way to go.
Fortunately since Git 2.13 I can override any settings (including user name and email) for all repositories located in a particular directory. Here's how my global
.gitconfig looks like now:
~$ cat ~/.gitconfig # This is Git's per-user configuration file. [user] name = wheleph email = email@example.com [core] excludesfile = /Users/wheleph/.gitignore [pull] ff = only [includeIf "gitdir:~/dm_repos/"] path = ~/dm_repos/.gitconfig
I keep all work repositories in directory
~/dm_repos and also there I have this "override" file:
~$ cat ~/dm_repos/.gitconfig [user] name = Volodymyr Sobotovych email = firstname.lastname@example.org
With this approach all I have to care about is keeping my work repos in a given directory and Git will take care of using proper user name and email for my commits!
BTW Intellij Idea also respects this setting.