GitChanging Commit Author

Fixing Commit Author Information

You committed using the wrong name or email — maybe you used your personal email on a work machine, or a CI bot committed under the root user. This page covers every scenario: fixing the last commit, fixing multiple commits with interactive rebase, and fixing all commits with a wrong email across the entire repository history.

First: configure Git correctly to prevent future mistakes

Set global author information

Bash
git config --global user.name "Jane Developer"
git config --global user.email "jane@company.com"

# Verify
git config --global user.name
git config --global user.email

# For a specific repo only (overrides global)
git config user.email "jane@personal.com"

Check the current author configuration

Bash
git config --list --show-origin | grep user
# file:/Users/jane/.gitconfig    user.name=Jane Developer
# file:/Users/jane/.gitconfig    user.email=jane@company.com
Fix the last commit only

Amend author on most recent commit

Bash
# Fix both name and email in one command
git commit --amend --author="Jane Developer <jane@company.com>" --no-edit
# [main abc1234] Your commit message
# Author: Jane Developer <jane@company.com>
# Date:   Mon Jan 13 15:00:00 2025 +0000

Reset author to current git config

Bash
# If git config is already correct, just reset author to config values
git commit --amend --reset-author --no-edit
Warning
`git commit --amend` rewrites the commit — the commit hash changes. If this commit was already pushed to a shared branch, you will need to force-push, which affects teammates.
Fix multiple commits with interactive rebase

If the wrong author is on several recent commits, use interactive rebase to step through each one and amend it.

Rebase interactively over the last 4 commits

Bash
git rebase -i HEAD~4
# Opens your editor with a list:
# pick abc1234 Add login feature
# pick def5678 Fix validation bug
# pick ghi9012 Update styles       ← wrong author
# pick jkl3456 Add tests           ← wrong author

Change 'pick' to 'edit' for commits to fix

Text
pick abc1234 Add login feature
pick def5678 Fix validation bug
edit ghi9012 Update styles
edit jkl3456 Add tests

Fix each commit when rebase pauses

Bash
# Rebase pauses at ghi9012
git commit --amend --author="Jane Developer <jane@company.com>" --no-edit
git rebase --continue

# Rebase pauses at jkl3456
git commit --amend --author="Jane Developer <jane@company.com>" --no-edit
git rebase --continue

# All done
# Successfully rebased and updated refs/heads/main.
Fix all commits with a specific wrong email (entire history)

If you need to update the author across the entire repository history — for example, you used a personal email for months — use git filter-repo.

Warning
Rewriting the entire commit history changes every commit hash in the repository. All teammates must re-clone, and all open pull requests will reference stale commit hashes. Co-ordinate this with your team and pick a quiet moment to do it.

Fix all commits with wrong email using filter-repo

Bash
# Install filter-repo if needed: pip install git-filter-repo

# Create a mailmap file
cat > mailmap.txt << 'EOF'
Jane Developer <jane@company.com> <jane@personal.com>
Jane Developer <jane@company.com> <root@ci-server>
EOF

# Apply the mailmap to rewrite all commit author and committer fields
git filter-repo --mailmap mailmap.txt

Alternative: use a Python callback for complex remapping

Bash
git filter-repo --email-callback '
  return email.replace(b"old@wrong.com", b"jane@company.com")
'
Fix using git filter-repo --commit-callback (full control)

Rewrite both author name and email

Bash
git filter-repo --commit-callback '
  if commit.author_email == b"root@localhost":
    commit.author_name = b"Jane Developer"
    commit.author_email = b"jane@company.com"
    commit.committer_name = b"Jane Developer"
    commit.committer_email = b"jane@company.com"
'
After rewriting history: force-push

Push the rewritten history

Bash
# filter-repo removes the origin remote as a safety measure
git remote add origin https://github.com/user/repo.git

# Force-push all branches
git push origin --all --force-with-lease
git push origin --tags --force-with-lease
Comparison: which method to use

Scope

Method

History impact

Last commit only, not pushed

git commit --amend --author

Single commit hash changes

Last commit, already pushed

git commit --amend + force-push

Single commit; warn teammates

Last N commits

git rebase -i HEAD~N + amend

N commits rewritten

All commits with wrong email

git filter-repo --mailmap

All commit hashes change

Complex remapping logic

git filter-repo --commit-callback

All commit hashes change

Verifying the fix

Check author on recent commits

Bash
git log --format="%h %an <%ae> %s" -10
# abc1234 Jane Developer <jane@company.com> Add login feature
# def5678 Jane Developer <jane@company.com> Fix validation bug
# ghi9012 Jane Developer <jane@company.com> Update styles

Find all unique authors in the repository

Bash
git log --all --format="%an <%ae>" | sort -u
# CI Bot <ci@build-server.internal>
# Jane Developer <jane@company.com>
# Root User <root@localhost>         ← these should be fixed
Using .mailmap for display-only correction

If you only want to correct how author names appear (without rewriting history), Git supports a .mailmap file in the root of the repository. This does not change any commit hashes — it only affects display in git log and git shortlog.

.mailmap file format

Text
# Canonical name <canonical email> <old email>
Jane Developer <jane@company.com> <jane@personal.com>
Jane Developer <jane@company.com> <root@localhost>

# Canonical name <canonical email> Old Name <old email>
Jane Developer <jane@company.com> Jane D <jane@old-employer.com>

Verify .mailmap is working

Bash
git shortlog -sne
#     47  Jane Developer <jane@company.com>
#      3  CI Bot <ci@build-server.internal>
Tip
For open-source projects, prefer `.mailmap` over history rewriting — it corrects the display without changing commit hashes, keeping git blame and bisect working correctly for everyone who already has the repository.
Prevention: per-directory author overrides
  • Use git config user.email (no --global) inside work repos to override the global email.

  • Add an includeIf block in ~/.gitconfig to auto-switch configs based on directory path.

~/.gitconfig with conditional include

Text
[user]
  name = Jane Developer
  email = jane@personal.com

[includeIf "gitdir:~/work/"]
  path = ~/.gitconfig-work

~/.gitconfig-work

Text
[user]
  email = jane@company.com