Git
GitHub
user authentication
version control
troubleshooting

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.

Practice system design

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.

bash
1git config user.name
2git config user.email
3git config --global user.name
4git config --global user.email

If the local repository should use a different identity than your global default, set it explicitly:

bash
git config user.name "Correct User"
git config user.email "[email protected]"

This only affects future commits unless you rewrite existing history.

Check Which Remote Credentials Are Being Used

Now inspect the remote URL.

bash
git remote -v

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:

bash
git remote set-url origin https://github.com/your-user/repo.git

Switch SSH remote:

bash
git remote set-url origin [email protected]:your-user/repo.git

If you use multiple GitHub accounts over SSH, configure separate keys and SSH host aliases in ~/.ssh/config.

Example:

sshconfig
1Host github-work
2    HostName github.com
3    User git
4    IdentityFile ~/.ssh/id_ed25519_work
5
6Host github-personal
7    HostName github.com
8    User git
9    IdentityFile ~/.ssh/id_ed25519_personal

Then use the alias in the remote URL:

bash
git remote set-url origin git@github-work:your-org/repo.git

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:

bash
git commit --amend --reset-author

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.

bash
git log --format="%h %an <%ae>" -n 3
git push

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.email for work repos.
  • Use SSH aliases for multiple GitHub accounts.
  • Check git remote -v before 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.email and 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.name and user.email separately 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.