Dual identity git

So we’ve all had the problem of getting me@home.com 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.

This ‘includeIf’ was added in git 2.13. So you should have it (side node: have you updated your git in the last few days? There’s CVE-2018-11235 out (PoC of exploit).

        ui = auto
        default = current
        editor = vi
        tool = vimdiff
        gpgsign = true

[includeIf "gitdir:~/src-ag/"]
  path = .gitconfig-work

[includeIf "gitdir:~/src/"]
  path = .gitconfig-home






Leave a Reply

Your email address will not be published. Required fields are marked *