Fixing AI agents and git pushing to the wrong GitHub account with per-folder config

Developers using several GitHub accounts on one machine often find that commits, pushes, and pull requests from tools like Claude Code go out under the wrong identity. The article explains that three separate settings decide the account: the git commit author, the credential used for pushes, and the GitHub CLI's active account. Common workarounds such as SSH host aliases, conditional email config, switching accounts manually, or using direnv with tokens each cover only part of the problem. The proposed fix organizes projects into per-account folders and uses git's includeIf directive along with a custom credential helper that pulls the right token from the GitHub CLI. The author also notes that git can select SSH keys per repository, which removes the need for host aliases when using SSH remotes.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in