Rewrite Git History
If you have multiple git
profiles, you will eventually mistakenly push a commit from the wrong author. For example, if you have a work and personal git account, and you write a quick patch for a personal project and commit the code from your work account, your "collaborators" on Github will show your work account.
If you wish to fix this, you can use the steps below to rewrite Git history, replacing any reference to your work profile with your personal one.
Requirements
- Python (if you're on Linux or Mac, you do not need to install this).
- The
git-filter-repo
package- Install with
pip install git-filter-repo
- Install with
Steps
Clone the repository in a new directory using the --bare
flag, i.e.: git clone --bare git@github.com:user/repo.git
. This will create a local copy of your repository's HEAD refs; you will not see your code, but instead will see directories like branches/
, tags/
, etc. This is essentially the metadata for your repository, as well as the git history.
Run a command like the following, replacing the Old Name
, old.email@example.com
, New Name
, and new.email@example.com
with your old/new author:
Clean your refs and ensure proper pruning:
Finally, force-push your changes:
Re-clone the repository, this time without --bare
, and use git log --author="Old Name"
to ensure all refs have been removed.