I have two GitHub accounts, one personal and one for work. For a long time I dealt with this by manually setting user.email per repo, forgetting to do it, and then having commits with the wrong identity. Not great.

The fix is includeIf in your git config. It lets you conditionally load a separate config file based on where the repo lives on disk.

My repos are organized under ~/ghq/github.com/, and work repos go under ~/ghq/github.com/GRITSpot/. That structure is what makes this work cleanly.

The main config

~/.config/git/config has the personal defaults:

[user]
    name = cacarico
    email = caio.quinilato@gmail.com
    signingkey = FCFDEA8966F8FA8B0296B9E80B5D2872304AD213

[commit]
    gpgsign = true

[tag]
    gpgSign = true

[includeIf "gitdir:~/ghq/github.com/GRITSpot/"]
    path = ~/.config/git/config-beat

[alias]
    pf = push --force-with-lease

[pull]
    rebase = false

The includeIf block says: if the current repo lives under ~/ghq/github.com/GRITSpot/, load config-beat on top of this config. Anything in that file overrides the defaults above.

The work config

~/.config/git/config-beat just overrides the identity:

[user]
    name = cacarico
    email = caio.quinilato@beat81.com
    signingkey = 52D0703DEE77DC65855E4EBAD3D5CEEEABFCEF2E

[commit]
    gpgsign = true

[tag]
    gpgSign = true

That’s it. When I’m inside a work repo, git picks up the work email and work GPG key. Outside of it, it falls back to personal. No manual setup per repo, no forgotten configs.