Rename user and email in git commit history

There seems to be different ways on how to do it, but this one worked best for me:

Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.

YouTube privacy policy

If you accept this notice, your choice will be saved and the page will refresh.

This is the shell script referenced in the video: replace-git-commit-author.sh

#!/bin/sh

git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

Step by step instructions

  1. git clone --bare https://GITURL.git
  2. adjust and run replace-git-commit-author.sh
  3. make sure to set local config
    • git config --local user.name "Your Correct Name"
    • git config --local user.email "your-correct-email@example.com"
  4. git push --force --tags origin 'refs/heads/*'