How Do I Change the Author and Committer Name/Email for Multiple Commits?

Better Stack Team
Updated on June 24, 2024

To change the author and committer name/email for multiple commits, you can use the git filter-branch command with the --env-filter option. This allows you to rewrite commit history by modifying environment variables.

First, create a script that updates the author and committer information. Open your text editor and create a script, for example, change-author.sh, with the following content:

 
#!/bin/bash

git filter-branch --env-filter '

OLD_EMAIL="old-email@example.com"
CORRECT_NAME="New Author Name"
CORRECT_EMAIL="new-email@example.com"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

Replace old-email@example.com with the old email address, New Author Name with the new author name, and new-email@example.com with the new email address.

Make the script executable using the following command:

 
chmod +x change-author.sh

Execute the script to rewrite the commit history:

 
./change-author.sh

After rewriting the commit history, force-push the changes to the remote repository:

 
git push --force --tags origin 'refs/heads/*'

Note:

  • Rewriting commit history can cause issues if the commits have already been pushed to a shared repository and other collaborators have based their work on them. Use it with caution.
  • After rewriting commit history, collaborators who have pulled the changes will need to rebase their work to incorporate the updated history.
  • Consider communicating any changes to other collaborators to avoid confusion.
Got an article suggestion? Let us know
Explore more
Git
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github