Create an alias to simplify our lifes
git config --global alias.change-commits '!'"f() { VAR=\$1; OLD=\$2; NEW=\$3; shift 3; git filter-branch --env-filter \"if [[ \\\"\$\`echo \$VAR\`\\\" = '\$OLD' ]]; then export \$VAR='\$NEW'; fi\" \$@; }
Change the author and the committer emails on all commits
git change-commits GIT_AUTHOR_EMAIL "old@example.com" "new@example.com" -f -- --all
git change-commits GIT_COMMITTER_EMAIL "old@example.com" "new@example.com" -f -- --all
Without changing both, github would complain that the GPG signatures were invalid
Finally apply the GPG signatures on all commits
git filter-branch --commit-filter 'git commit-tree -S "$@";' -f -- --all
NOTE: to apply to a range of commits use:
HEAD~4..HEAD
instead of-- --all
To verify if everything is correctly use:
git log --show-signature --format=full
To sign future commits:
git config --global user.signingkey 5500BCA970D62D2D5614BCA242B23084B718647A
git config --global commit.gpgsign true
replace
5500BCA970D62D2D5614BCA242B23084B718647A
by your own key id
If the github is giving the wrong datetimes use
--committer-date-is-author-date
on your rebase