Q. All my git commits got pushed to GitHub with username of another account. Is there a way I can update the username on GitHub and local git too ?

Yes, you can fix this easily! This happens when your global or local Git configuration has a different username or email associated with it than your intended GitHub profile.

Here is how to fix it locally, rewrite your commit history so the correct author shows up, and update it on GitHub.

Step 1: Update your local Git configuration

Run these commands in your project terminal to set your correct name and email. Replace "Your Correct Name" and "your.email@example.com" with your actual GitHub account details:

Bash

# Set it specifically for this project repository
git config user.name "Your Correct Name"
git config user.email "your.email@example.com"

# (Optional) Set it globally for all future projects on this machine
git config --global user.name "Your Correct Name"
git config --global user.email "your.email@example.com"

Step 2: Rewrite the commit history author

Since you just made those chunked commits, you want to amend their author metadata to reflect your correct identity. Run this command in your terminal to update all past commits in your current branch:

Bash

git commit --amend --reset-author --no-edit
# OR if you have multiple recent commits you want to fix at once, run an interactive rebase or use this filter-branch command:

Wait, since you have multiple recent commits in a row, the cleanest way to fix the author across all of them is using an interactive rebase:

  1. Run: git rebase -i HEAD~4 (assuming you have 4 recent commits to fix).

  2. In the text editor that pops up, change the word pick to edit for all of the listed commits. Save and close.

  3. For each commit that pauses, run:

    Bash

    git commit --amend --allow-empty --reset-author --no-edit
    git rebase --continue
    

Step 3: Force push to GitHub

Because you rewrote the commit history, Git’s history will diverge from what is currently on GitHub. You will need to force push the updated history to your remote repository:

Bash

git push origin main --force

Once you do this, refresh your private GitHub repository page, and you will see your correct username and avatar attached to all of your well-crafted chunks!



Q. will it mess up the commit history and their timestamp ?

It will preserve your commit order and narrative structure, but it will update the author timestamps to the exact moment you run the amend/rebase command.

Here is the exact impact:

  • Commit Order & Chunks: Completely preserved. Your 4 logical steps will remain intact and in the exact same sequence.

  • Timestamps: By default, --reset-author updates the author date to the current time. If you want to keep your original creation timestamps while only changing the username and email, you can use GIT_COMMITTER_DATE and GIT_AUTHOR_DATE during the amend, or use an easier automated one-liner script instead of manual rebase.

Alternative: A Clean One-Liner to Fix Author Name/Email Without Rewriting History Timestamps

If you want a safe script that fixes your name and email across all local commits without messing up your workflow or manual rebase steps, you can run this standard Git filter command in your terminal:

Bash

git filter-branch --env-filter '
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your.correct.email@example.com"

export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
' HEAD

After running that, check your log (git log), verify that your correct username and email appear on every commit, and then push it up:

Bash

git push origin main --force

This safely updates the identity metadata across your chunked history while keeping everything else pristine!