Sometimes you need to rewrite your email across all commits in a git repository.
Note (2026): This post originally used
git filter-branch, which has been deprecated since Git 2.24. The modern equivalent isgit filter-repo. Thefilter-branchcommand below still works but is no longer recommended.
With git filter-branch (deprecated)#
git filter-branch --env-filter '
if [ $GIT_AUTHOR_EMAIL = bad@email ]; then
GIT_AUTHOR_EMAIL=correct@email
fi
export GIT_AUTHOR_EMAIL
'Modern equivalent: git-filter-repo#
pip install git-filter-repo
git filter-repo --email-callback '
return email if email != b"bad@email" else b"correct@email"
'For collaborators#
After a history rewrite, collaborators need to react. Per Jakub Narębski:
- If they didn’t base any work on pre-rewrite history:
git reset --hard origin/masterorgit pull origin(fast-forward). - If they did base work on it:
git rebase origin/masterorgit pull --rebase origin.
