Clean up historyAlways fixable

Fix the wrong author or email on your commits

My commits show the wrong name or email — how do I fix them?

Short answer

Set the correct identity with git config, then fix the last commit with git commit --amend --reset-author. For a range of commits use git rebase with an exec step, or git filter-repo --mailmap to rewrite the whole history at once.

quick fix
git config user.email "you@example.com"
git commit --amend --reset-author --no-edit

Fixes the author on the most recent commit

Does this match your situation?

  • Commits are attributed to a work email on a personal project (or the reverse).
  • Your contributions don't appear on your GitHub profile.
  • Commits show a default username like 'root' or 'user@localhost'.

Step-by-step fix

  1. Fix the configuration first

    Otherwise every new commit repeats the mistake. Set it globally for your default identity and locally in any repository that needs a different one.

    step 1
    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    
    # just this repo:
    git config user.email "work@company.com"
    
    git config --list --show-origin | grep user.
    
  2. Fix the most recent commit

    --reset-author restamps the commit with your current identity and refreshes the timestamp, while --no-edit keeps the message unchanged.

    step 2
    git commit --amend --reset-author --no-edit
    
  3. Fix a specific older commit

    You can also set the author explicitly, which is useful when correcting a single commit somewhere back in history via an interactive rebase.

    step 3
    git rebase -i HEAD~5
    # mark the commit as 'edit', then:
    git commit --amend --author="Your Name <you@example.com>" --no-edit
    git rebase --continue
    
  4. Fix many commits at once

    For a whole branch, an exec step reruns the amend on every replayed commit. For an entire repository history, filter-repo with a mailmap is the right tool.

    step 4
    git rebase -r --exec 'git commit --amend --reset-author --no-edit' HEAD~10
    
    # whole history:
    printf 'Your Name <you@example.com> <old@wrong.com>\n' > ../mailmap.txt
    git filter-repo --mailmap ../mailmap.txt
    
  5. Push the rewritten history

    Every rewritten commit has a new hash, so the remote will reject an ordinary push.

    step 5
    git push --force-with-lease
    

    Coordinate first if anyone else works on the branch — they'll need to re-clone or reset.

Why this works

Author name and email are stored inside the commit object itself and contribute to its hash, so correcting them necessarily creates new commits. Git also distinguishes author (who wrote the change) from committer (who applied it) — an amend updates the committer automatically, but the author only changes if you ask, which is what --reset-author does. Hosting platforms match commits to accounts purely by the email address, which is why a typo there makes your contributions vanish from your profile despite the name looking right.

How to stop it happening again

  • Set user.name and user.email globally the moment you install Git on a new machine.
  • Use conditional includes in ~/.gitconfig to switch identity automatically by directory.
  • Add every address you commit from to your GitHub account so nothing goes unattributed.

Commands used in this guide

git config

Read and write Git settings for one repo, your user, or the whole machine.

git commit --amend

Replace the most recent commit instead of stacking another one on top.

git rebase -i

Reorder, squash, split, reword or drop your recent commits.

git filter-repo

Rewrite an entire repository's history - the supported way to purge a leaked secret or a huge file.

git push

Upload your commits to the remote repository.

Still stuck?

Search the full command reference and every other rescue guide — there are 56 of them, covering everything from detached HEAD to force-push disasters.

Browse all guides →

Frequently asked questions

How do I change the author of the last commit?

Set the right identity with git config, then run git commit --amend --reset-author --no-edit. That restamps the commit with your current name and email while leaving the message alone.

Why don't my commits show up on my GitHub profile?

GitHub links commits to accounts by email address. If you committed with an address that isn't registered on your account, the contribution isn't attributed. Add the address in GitHub's email settings, or rewrite the commits with the correct one.

How do I change the author on all commits in a repository?

git filter-repo --mailmap with a mailmap file mapping old identities to new ones. It rewrites every commit in one pass and is far safer and faster than the old filter-branch approach. Everyone will need to re-clone afterwards.

What's the difference between author and committer?

The author wrote the original change; the committer created the commit object. They differ when someone applies a patch on your behalf, or after a rebase or cherry-pick — the author is preserved while the committer becomes whoever ran the command.

Related rescue guides

← All Git Rescue guides