Skip to main content

Rewriting your email in git commits

·147 words·1 min
Kostiantyn Lysenko
Author
Kostiantyn Lysenko

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 is git filter-repo. The filter-branch command 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/master or git pull origin (fast-forward).
  • If they did base work on it: git rebase origin/master or git pull --rebase origin.

References
#


comments powered by Disqus