Note
Previously, people used git filter-branch
to accomplish the same task. However, it shouldn't be used anymore, as it's somewhat deprecated as of Git 2.24, Q4 2019. Instead, we can now use git filter-repo
.
Installation
brew
If you're using macOS, you can use Homebrew.
$ brew install git-filter-repo
After installation, you can use either git filter-repo
or git-filter-repo
.
pip
Alternatively, you can use pip
to install the package:
$ python3 -m pip install --user git-filter-repo
Once the installation is complete, if you can't use git filter-repo
or git-filter-repo
, check your PATH. Alternatively, you can use it as shown below:
$ <PATH TO PYTHON>/<VERSION>/bin/git-filter-repo
mailmap
To use git filter-repo
, you'll need to prepare a mailmap file, which is used to replace your old author names and emails with the new ones. The syntax for the mailmap file is as follows:
Correct Name <correct@email.com> OLD NAME1 <old@email1.com> Correct Name <correct@email.com> OLD NAME2 <old@email2.com>
Feel free to add as many OLD NAME
and OLD EMAIL
entries as necessary for multiple author names that need to be changed.
For example,
Jii Yoo <jiiyoo@tuta.io> John Doe <john@doe.com> Jii Yoo <jiiyoo@tuta.io> John Doe <johndoe@example.com> Jii Yoo <jiiyoo@tuta.io> Jane Doe <jane-doe@example.com>
git filter-repo
Please note that you need a freshly cloned repository. If you are performing this on an existing repository, it's advisable to re-clone it.
$ cd repo repo/$ git filter-repo --mailmap your-mailmap
After completing the task, the origin
remote will be automatically removed. To restore it, you will need to add the origin
back to your repository using the following command:
repo/$ git remote add origin REPO-URL