Recommended, so you can easily roll back if you mess up.
Push your work.
Or make a duplicate branch.
$ git checkout main
$ git checkout -b main-backup
$ git checkout main
Also make sure that if others are working on the repo as you that they are expecting this change.
The script will do a rebase of all commits. Even if the email address is not matched, the rebase will still be done.
You are overwriting git history by editing commits and not adding new ones on top of the old and so will have to a do force push at the end.
This affects the email of both commit author and committer fields.
$ ~/scripts/rewrite_author.sh OLD_EMAIL NEW_MAIL
$ rewrite_author.sh OLD_EMAIL NEW_MAIL
git log
to verify your changes. $ git push --force
$ git fetch
$ git reset --hard origin/main # or origin/master
Sample output of the script.
Rewrite 80b85af8f4454c2c7b820ed13229897262f18bb2 (11/14) (1 seconds passed, remaining 0 predicted)
Ref 'refs/heads/main' was rewritten
Ref 'refs/heads/test' was rewritten
Ref 'refs/tags/v0.1.0' was rewritten
Okay so you messed up your main branch.
Here is how to undo.
Warning the tags got rewritten, and the steps here will not bring them back.
Assuming the content on the remote (like GitHub) is good, do this:
$ git fetch
$ git reset --hard origin/main
If you used a back-up branch, restore from that:
$ git reset --hard main-backup