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.
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
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 1git 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.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 2git commit --amend --reset-author --no-editFix 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 3git rebase -i HEAD~5 # mark the commit as 'edit', then: git commit --amend --author="Your Name <you@example.com>" --no-edit git rebase --continueFix 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 4git 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.txtPush the rewritten history
Every rewritten commit has a new hash, so the remote will reject an ordinary push.
step 5git push --force-with-leaseCoordinate 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 configRead and write Git settings for one repo, your user, or the whole machine.
git commit --amendReplace the most recent commit instead of stacking another one on top.
git rebase -iReorder, squash, split, reword or drop your recent commits.
git filter-repoRewrite an entire repository's history - the supported way to purge a leaked secret or a huge file.
git pushUpload 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
How do I edit a Git commit message?
For the most recent commit, git commit --amend -m "new message" replaces it. For older commits, git rebase -i lets you mark any of them as reword. Both rewrite history, so if the commit is already pushed you'll need git push --force-with-lease and a word to your team.
Read the fix →Always fixableHow do I combine multiple commits into a single commit?
git rebase -i HEAD~n opens an editor where you mark commits as squash or fixup to fold them into the one above. For a quick all-in-one collapse, git reset --soft HEAD~n followed by a fresh commit achieves the same result with no editor at all.
Read the fix →Always fixableI committed a secret — how do I remove it from Git history?
Rotate the secret first — that's the only step that genuinely protects you. Then purge it from history with git filter-repo (or the BFG Repo-Cleaner) and force-push. Deleting the file in a new commit does nothing, because the old commit still contains it and is still fetchable.
Read the fix →Always fixableHow do I undo the last commit but keep my work?
git reset --soft HEAD~1 removes the commit and leaves every change staged, ready to recommit. Use --mixed (the default) if you also want the changes unstaged, and only use --hard if you genuinely want the work destroyed. If the commit is already pushed, revert it instead of resetting.
Read the fix →