When working with multiple Git profiles (personal, work, side projects), it’s easy to accidentally commit code using the wrong author name or email. The problem becomes more serious when those commits are already pushed and merged into a shared branch like main or develop.
This guide explains how to safely fix the Git author and committer information in already pushed commits.
Important Note
This process rewrites Git history, changes commit SHA values, and requires a force push. Make sure to inform your team before performing these steps.
Recommended Tool
Use git filter-repo, the modern and recommended replacement for git filter-branch.
Steps to Fix the Author
1. Install the required tool
pip install git-filter-repo
2. Rewrite author and committer information
git filter-repo --commit-callback '
if commit.author_email == b"WrongEMAIL@email.com" or commit.committer_email == b"WrongEMAIL@email.com":
commit.author_name = b"CorrectName"
commit.author_email = b"CorrectEMAIL@email.com"
commit.committer_name = b"CorrectName"
commit.committer_email = b"CorrectEMAIL@email.com" ' --force
3. Re-add the remote repository
git filter-repo removes remotes by design as a safety measure.
git remote add origin https://github.com/your-org/your-repo.git
git remote -v
4. Force push the rewritten history
git push origin --force --all
git push origin --force --tags
5. Sync local branch
git fetch origin
git reset --hard origin/main
Verify the Fix
git log --all --pretty=format:'%h | %an | %ae'
Prevent This in the Future
Set Git identity per repository:
git config user.name "CorrectName"
git config user.email "CorrectEMAIL@email.com"
For multiple identities, configure conditional Git profiles using includeIf in .gitconfig.
Conclusion
Using the wrong Git author is a common mistake, especially when switching between multiple repositories and identities. Even if commits are already pushed and merged, the issue can be fixed cleanly and safely using git filter-repo with proper coordination.