Git confuses people with two accounts because "who you are" is actually two separate questions: identity (what name/email goes on a commit) and authentication (which account is allowed to push). Identity comes from user.name and user.email in Git config; authentication comes from your credential (Git Credential Manager login / personal access token) over HTTPS, or your SSH key over SSH. They are configured in different places and can disagree — which is exactly why your commits show the wrong author or your push comes from the wrong account. Once you see the two layers, multi-account setups stop being magic.
git config user.name/user.email. Push account = credential helper (HTTPS) or SSH key. Fix them separately, per repository or per folder — or use a client like GITmaxed that binds both to each repository for you.
The two layers, side by side
| Identity (author) | Authentication (pusher) | |
|---|---|---|
| Question it answers | "Whose name goes on this commit?" | "Which account may write to this repository?" |
| Where it's set | user.name, user.email in Git config | Credential manager (HTTPS) or SSH key (SSH) |
| Chosen by | The folder/repository you're in (if configured) | The remote URL shape + stored credentials/keys |
| Checked with | git var GIT_AUTHOR_IDENT | ssh -T git@github.com or your sign-in prompt |
| Wrong value looks like | Commit shows the other account's name on GitHub | Push rejected, or attributed to the wrong account |
How a commit gets its author
Every commit stores a name and email at creation time. GitHub then matches that email to an account — that's how your avatar appears on the commit. If your email belongs to account A, the commit is A's work, no matter which account pushes it. This is why changing sign-ins in a GUI without changing user.email produces "wrong author" commits:
# who am I right now, in this repository?
git var GIT_AUTHOR_IDENT
# → Work Name <me@company.com> ...
# set identity for this one repository only
git config user.name "Work Name"
git config user.email "me@company.com"
# set identity for everything (single-account users)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
How a push chooses its account
Pushing is a separate conversation with GitHub. What you present is decided by the remote URL:
https://github.com/owner/repo.git— GitHub asks for a credential. On Windows, Git Credential Manager (bundled with Git for Windows) pops a browser sign-in and stores the resulting token in Windows Credential Manager. With two accounts, the stored login per repository decides who pushes.git@github.com:owner/repo.git— GitHub checks the SSH key you offer. Each key is uploaded to exactly one account, so the key identifies the account. That's why multi-account users keep one key per account.
Why two accounts break the default setup
A default install has one global identity and one cached credential. The first account you sign into owns everything. The second account's repository then hits one of two failures: pushes authenticate as the wrong account (credential collision), or commits carry the wrong author (identity collision) — often both at once. The fix is always the same shape: make at least one of the layers per-repository or per-folder.
- Identity per folder:
includeIfrules load a differentuser.*under each folder tree (full tutorial in Git includeIf: Switch Identity by Folder). - Authentication per repository: HTTPS with
useHttpPathstores one login per repository; SSH with one key per account separates by URL shape. - Both layers per repository, managed: a multi-account client (GITmaxed) binds account identity + token to each repository, so neither layer can drift.
Debugging checklist when "Git uses the wrong account"
git remote -v— is this repo HTTPS or SSH? That tells you which authentication layer is in play.git var GIT_AUTHORIDENT— is the author the account you expect? If not, fixuser.email(repository-local or folder config).ssh -T git@github.com(SSH repos) — the greeting names the account the key belongs to.- HTTPS repos: watch the first sign-in prompt, or check Credential Manager for the stored
git:entry — that's the pusher. - Pushed already with the wrong author? The author is baked into the commit — amend the email and force-push while it's still private/unshared.
Or skip both layers entirely
Everything above is the mental model you need — and it's also exactly what a multi-account Git client maintains for you. GITmaxed keeps one OAuth token per account and one binding per repository: commits are authored as the bound account, pushes authenticate as the bound account, and there is no global identity to get wrong. Learn the layers so nothing surprises you; then let the tool carry them.
Related questions answered (the same queries, one by one)
Why does my commit show the wrong name on GitHub?
Because user.email at commit time matched a different account. Check git var GIT_AUTHORIDENT in that repository and set git config user.email to the address of the account you intend.
Does git config user.email have to match my GitHub account?
For attribution, yes — GitHub links commits to the account owning that email (verified or not). For pushing, no — that's the credential layer.
How does Git know which account to push with?
It doesn't "know" — the remote URL shape picks the layer: HTTPS uses the stored credential (per repository if useHttpPath is on), SSH uses the offered key. That's why per-repo credentials or per-account keys are required for two accounts.
Can identity and authentication be different accounts in one commit?
Yes — author comes from config, pusher from credentials. That's a common accident ("right author, wrong pusher" or vice versa) and a reason to bind both per repository, as GITmaxed does.
What is the difference between user.name and GitHub username?
user.name is free text stored in the commit; your GitHub username is the account. GitHub shows the account linked to your commit email, regardless of what user.name says.
How do I check which GitHub account Git is using right now?
Identity: git var GIT_AUTHORIDENT. SSH pusher: ssh -T git@github.com. HTTPS pusher: the login you approved in Credential Manager / the sign-in prompt. CLI: gh auth status --active.
No comments:
Post a Comment