How to Rename Author on All Commits in Git

In Git, there may be situations where you need to update or correct author information on all commits, such as changing email addresses or fixing incorrect names. This guide will explain how to rename authors on all commits using the git-filter-repo tool.

Requirements

  1. git-filter-repo: You can install it from the official repository at https://github.com/newren/git-filter-repo.

Procedure

Step 1: Create a .mailmap File

Create a file named .mailmap in the root directory of your Git repository. This file will map the old author information to the new author information. The correct format for each entry is as follows:

Target Name <[email protected]> Original Name <[email protected]>

Replace “Target Name” with the desired new author’s name and “[email protected]” with their new email address. Similarly, replace “Original Name” with the original author’s name and “[email protected]” with their original email address.

Step 2: Run the git-filter-repo Command

Execute the following command in your terminal:

1
git-filter-repo --mailmap .mailmap

This command applies the changes specified in the .mailmap file to all commits in your Git repository, effectively renaming the authors.

Step 3: Add a Remote URL (Optional)

If your repository doesn’t have a remote URL set, you can add it using the following command:

1
git remote add origin [REMOTE_URL]

Replace [REMOTE_URL] with the URL of your remote repository.

Conclusion

By following these steps, you can successfully rename author information on all commits in your Git repository using the git-filter-repo tool. This method ensures consistency and accuracy of authorship information across your commits.

Note: It’s always recommended to back up your repository before making any significant changes like author renaming. Additionally, it’s crucial to communicate and collaborate with your team members when making such modifications to maintain transparency and avoid any unintended consequences.

0%