Skip to content

Instantly share code, notes, and snippets.

@jolacdev
Created February 8, 2025 11:26
Show Gist options
  • Save jolacdev/20e8c880555b019fb80e3218c5ab33ac to your computer and use it in GitHub Desktop.
Save jolacdev/20e8c880555b019fb80e3218c5ab33ac to your computer and use it in GitHub Desktop.

Git Commit History - Change Email and Name

Disclaimer: This guide was done using Windows. The installation steps and commands may vary for other operating systems.

Author and committer email and name can be updated in the Git history using git-filter-repo.

Note: You will need Python 3 and the git-filter-repo tool to run the commands. Below is how I added it on Windows:

Installation on Windows:

  1. Install Python 3:

    • Download and install Python 3 from the official site: python.org.
    • During installation, make sure to check the box to add Python to your system PATH.
  2. Install git-filter-repo:

    • Open your terminal (e.g., PowerShell or Command Prompt) and run the following command to install git-filter-repo via pip:
      pip install git-filter-repo
  3. Verify Installation:

    • To verify that the installation was successful, run the following command inside a Git repository:
      python -m git_filter_repo --analyze

1. Change Author/Committer Email

The following command will replace all instances of an old email with a new one in both the author and committer fields of every commit in the history.

python -m git_filter_repo --commit-callback "
if commit.author_email == b'old_email':
    commit.author_email = b'your_github_no_reply_email@users.noreply.github.com'
if commit.committer_email == b'old_email':
    commit.committer_email = b'your_github_no_reply_email@users.noreply.github.com'
"

2. Change Author/Committer Name

The following command will replace all instances of an old name with a new one for both the author and committer names.

python -m git_filter_repo --commit-callback "
if commit.author_name == b'Old Name':
    commit.author_name = b'New Name'
if commit.committer_name == b'Old Name':
    commit.committer_name = b'New Name'
"

Notes

  • Make sure to replace old_email, your_github_no_reply_email@users.noreply.github.com, Old Name, and New Name with your actual values.
  • After running these commands, you may need to push the rewritten history to your remote repository using git push --force.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment