Rewrite Git Username and Email History

Simple script to rewrite your username and email for all past git commits. Run it in the folder containing a local Git repository.

git filter-branch -f --env-filter '
WRONG_EMAIL="wrong@email.com"
NEW_NAME="New Username"
NEW_EMAIL="new@email.com"

if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$NEW_NAME"
    export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$NEW_NAME"
    export GIT_AUTHOR_EMAIL="$NEW_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

To push changes to the remote repository (Github), it’s easiest to delete the repo and recreate it. Then push to the newly create remote repository.

git remote remove origin
git remote add origin <remote repo>
git push -u origin master