Skip to content

Instantly share code, notes, and snippets.

@iSkore
Last active September 21, 2020 12:48
Show Gist options
  • Save iSkore/3e8628f115e248dd5ed71eb57f4915ce to your computer and use it in GitHub Desktop.
Save iSkore/3e8628f115e248dd5ed71eb57f4915ce to your computer and use it in GitHub Desktop.
Update all git branches, commits, & tags with new email & author

Git correct commit author

Start with:

git clone --bare https://github.com/user/repo.git
cd repo.git

TO CORRECT A SINGLE EMAIL

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

IF YOU ARE THE ONLY AUTHOR

git filter-branch -f --env-filter '
CORRECT_NAME="iSkore"
CORRECT_EMAIL="iSkore@users.noreply.github.com"
if [ "$GIT_COMMITTER_EMAIL" != "$CORRECT_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" != "$CORRECT_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

Push the corrected history to GitHub:

git push --force --tags origin 'refs/heads/*'

OR if you like to push selected references of the branches then use

git push --force --tags origin 'refs/heads/develop'

Credits:

@olivieradam666

http://stackoverflow.com/a/30737248/4863783

https://help.github.com/articles/changing-author-info/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment