Overview

When I started working at my current company, I was given a company email and GitHub account. However, one day I accidentally committed and pushed code using my personal GitHub account. This resulted in my commits being linked to my personal profile instead of the company one — not ideal for team visibility and tracking!

🎯 The Problem

I had commits with my personal email:

But I needed to replace them with my company email and name:

Name: Your Name
Email: [email protected]

🔧 The Solution

The basic syntax is git filter-branch

Here’s the command I used to rewrite the commit history and replace the email and name in all commits:

git filter-branch --force --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "[email protected]" ]; then
    GIT_COMMITTER_NAME="Your Name";
    GIT_AUTHOR_NAME="Your Name";
    GIT_COMMITTER_EMAIL="[email protected]";
    GIT_AUTHOR_EMAIL="[email protected]";
fi' -- --all

This scans the entire Git history and updates the name/email for all commits that match the personal email.

🚀 Push the Changes

After rewriting history, I force pushed the updated commits:

git push --force

⚠️ Caution: This rewrites history. Be extra careful when working in shared repositories!

✅ Lesson Learned

Now I always double-check my Git config:

git config user.name
git config user.email

This simple habit helps avoid future mix-ups!