Rewrite Old Commits with the Correct Info

If you already made commits with the wrong name/email and you want to fix your commit history, follow this:

 1git filter-branch --env-filter '
 2OLD_EMAIL="wrong@email.com"
 3CORRECT_NAME="Your Correct Name"
 4CORRECT_EMAIL="your.correct@email.com"
 5
 6if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]; then
 7    export GIT_COMMITTER_NAME="$CORRECT_NAME"
 8    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
 9fi
10if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]; then
11    export GIT_AUTHOR_NAME="$CORRECT_NAME"
12    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
13fi
14' --tag-name-filter cat -- --branches --tags

Rewrite every commit with the correct identity

This doesn’t care what the old name/email was — it just replaces everything! 💥

1git filter-branch --env-filter '
2export GIT_AUTHOR_NAME="Your Correct Name"
3export GIT_AUTHOR_EMAIL="your.correct@email.com"
4export GIT_COMMITTER_NAME="Your Correct Name"
5export GIT_COMMITTER_EMAIL="your.correct@email.com"
6' --tag-name-filter cat -- --branches --tags

Push it back to remote (forcefully!)

If you’ve already pushed this repo before, and want to update the remote with the fixed history:

1git push --force --tags origin main

Replace main with whatever your branch name is (master, dev, etc.)