Skip to content

Instantly share code, notes, and snippets.

@sohhamm
Created January 18, 2022 16:12
Show Gist options
  • Save sohhamm/c1ae9b745ba73aa614dee43d83381632 to your computer and use it in GitHub Desktop.
Save sohhamm/c1ae9b745ba73aa614dee43d83381632 to your computer and use it in GitHub Desktop.
Shell script to change your name and email in git commit history
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="old-email@test.com"
OLD_NAME="old name"
CORRECT_EMAIL="new-email@test.com"
CORRECT_NAME="new name"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
export GIT_COMMITTER_NAME="$CORRECT_NAME"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
export GIT_AUTHOR_NAME="$CORRECT_NAME"
fi
' --tag-name-filter cat -- --branches --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment