So we’ve all had the problem of getting firstname.lastname@example.org in the commit history of your work repo, or vice-versa. This causes problems with your GPG commits since your me@home email is not verified.
You can ‘solve’ it by putting hooks in to check for, and reject, and then religiously remember to set ‘git config user.email’ for each new repo so that the global doesn’t override.
You can write some magic bash alias that changes your HOME env variable. Why does GIT_CONFIG not work? Well, it only affects the ‘git config’ command, not the others like commit. Why? ¯\_(ツ)_/¯
But, I found, after years of just lightly suffering with this problem, that there is a better way. ‘includeIf’.
Now my ~/.gitconfig file looks like below. Side note: do you have your gpgsign set? If not, take a moment, setup a GPG master key, create a signing (sub) key, make sure your passphrase is long, and add your GPG pubkey to your git.
[color] ui = auto [push] default = current [core] editor = vi [merge] tool = vimdiff [commit] gpgsign = true [includeIf "gitdir:~/src-ag/"] path = .gitconfig-work [includeIf "gitdir:~/src/"] path = .gitconfig-home