DEV Community

Sandeep Shelke
Sandeep Shelke

Posted on AI-assisted

Wrong git email again? Pick the identity from the remote URL

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (2)

Collapse
 
nikkhielseath profile image
Nikkhiel Seath •

I wrote this old piece on gitconfig as I always tend to forget it. Nice to see that there is now a tool for this. Thank you for building it, @yantrakar ! :)

Collapse
 
yantrakar profile image
Sandeep Shelke •

Thank you @nikkhielseath! I went through it all too: user settings in each repo's .git/config, then global settings, then SSH keys per account. Each worked until it didn't. That's why I ended up matching on the remote URL. Would love first hand experience if you decide to use gitpro. cheers!