Git pushing to remote GitHub repository as wrong user
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Pushing to GitHub as the wrong user usually means one of two things: the commit metadata is wrong, or the remote authentication credentials are wrong. Those are separate problems and they need separate fixes. The first affects authorship history, while the second affects which GitHub account actually performed the push.
Distinguish Commit Identity From Push Identity
Git stores author and committer name and email inside each commit. GitHub authentication decides which account is allowed to push the commit to the remote repository.
That means you can have:
- Correct GitHub account pushing commits with wrong author email.
- Wrong GitHub account pushing commits with correct author email.
- Both wrong at the same time.
Start by checking both layers.
Check Local Git Configuration
Inspect the repository-level and global Git identity.
If the local repository should use a different identity than your global default, set it explicitly:
This only affects future commits unless you rewrite existing history.
Check Which Remote Credentials Are Being Used
Now inspect the remote URL.
If it uses HTTPS, your credential helper may be supplying a cached account. If it uses SSH, the active SSH key may belong to another GitHub user.
For HTTPS, clear or update cached credentials in your system credential manager. For SSH, test which account the key maps to:
GitHub will usually tell you which account authenticated.
Fix the Remote Authentication Path
If the wrong account is authenticating, update the remote or the credentials.
Switch HTTPS remote:
Switch SSH remote:
If you use multiple GitHub accounts over SSH, configure separate keys and SSH host aliases in ~/.ssh/config.
Example:
Then use the alias in the remote URL:
Fix Wrong Commits Already Created
If the push succeeded but commits carry the wrong author, fix them before sharing further if possible.
For the most recent commit:
For multiple recent local commits, interactive rebase or filter-based rewriting is possible, but only do that before others depend on the branch. Once the branch is shared, rewriting history becomes a coordination problem, not just a local fix.
Verify on GitHub
After correcting config and credentials, validate both push path and commit attribution.
Then confirm on GitHub that:
- The correct account performed the push.
- The commits show the intended author email.
- The email is associated with the correct GitHub account if you want the UI attribution to link properly.
Prevent It in Future
A practical prevention strategy:
- Use per-repository
user.emailfor work repos. - Use SSH aliases for multiple GitHub accounts.
- Check
git remote -vbefore first push in a new clone. - Keep one verified email per account and match commit email to it.
These habits are lower cost than cleaning up authorship and permissions later.
Common Pitfalls
- Fixing
user.emailand assuming that also fixes remote authentication. - Clearing remote credentials but forgetting existing commit metadata is still wrong.
- Using one SSH key for multiple accounts and expecting GitHub to guess the right identity.
- Rewriting shared branch history without coordination.
- Forgetting that GitHub UI attribution depends on email association, not only on displayed name.
Summary
- Wrong-user pushes usually involve either Git metadata, remote credentials, or both.
- Check local
user.nameanduser.emailseparately from remote auth settings. - Use SSH aliases or explicit credential setup when working with multiple GitHub accounts.
- Amend or rewrite commits only when history ownership needs correction.
- Prevent future mistakes with per-repo config and first-push remote verification.
Related reading
- GitLab remote HTTP Basic Access denied and fatal Authentication
- Given a private key, is it possible to derive its public key?
- GKE Google Managed Certificate with DNS authorization
- Gmail Error The SMTP server requires a secure connection or the client was not authenticated. The server response was 5.5.1 Authentication Required
- git rebase --continue won't work
- Git Rebase Conflict Who is HEAD?
- git rebase error cannot stat 'file' Permission denied
- Git remote branch deleted, but still it appears in ''branch -a''

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.