Personal GitHub, work GitHub, GitLab, two Bitbuckets. More than once I committed with the wrong name and email. Sometimes the push was rejected. Sometimes nobody noticed for weeks.

Why includeIf gitdir is not enough

It picks the identity by folder. Repos don't always live in the right folder. The remote URL is a better signal: git@bitbucket.org:client/api.git is a client repo wherever it is cloned.

Git can do this itself since 2.36:

[includeIf "hasconfig:remote.*.url:git@bitbucket.org:client/**"] path = ~/.gitconfig-client 

Add one SSH host entry per account, because GitHub and Bitbucket won't take the same key on two accounts.

Or let gitpro write it

gitpro is a small open-source CLI that writes exactly this: the includeIf blocks and the SSH entries, in a marked block, backed up first. No daemon, no git wrapper.

pipx install gitpro gitpro setup # preview, then confirm once gitpro why # which identity this repo should use, and the fix gitpro scan # find repos that override it 

scan found one old repo of mine with its own user.email that ignored everything. scan --fix removed it.

Coding agents commit as whoever git says you are, so there is also a Claude Code hook that blocks a wrong-identity commit or push.

Linux and macOS, MIT: github.com/Yantrakar/gitpro

Written with help from Claude. The experience and the tool are mine.