Could I change my name and surname in all previous commits?

GitGit Filter-Branch

Git Problem Overview

I would like to change my name, surname and email in my all commits, is it possible?

Git Solutions

Solution 1 - Git

Use git-filter-branch.

git filter-branch --commit-filter 'if [ "$GIT_AUTHOR_NAME" = "Josh Lee" ];
  then export GIT_AUTHOR_NAME="Hobo Bob"; export [email protected];
  fi; git commit-tree "$@"'

This only affects the author, not the committer (which for most commits will be the same as the author). If you want to rewrite those as well, set the GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL variables.

The standard warning about rewriting history applies; only do it to history that has not yet been shared.

June 2018 Update

The manual now includes a solution, using --env-filter, in its examples: :

git filter-branch --env-filter '
	if test "$GIT_AUTHOR_EMAIL" = "root@localhost"
		GIT_AUTHOR_EMAIL[email protected]
	if test "$GIT_COMMITTER_EMAIL" = "root@localhost"
		GIT_COMMITTER_EMAIL[email protected]
' -- --all

Solution 2 - Git

To rewrite both author and commiter in all selected commits:

git filter-branch --commit-filter \
'if [ "$GIT_AUTHOR_NAME" = "OldAuthor Name" ]; then \
export GIT_AUTHOR_NAME="Author Name";\
export GIT_AUTHOR_EMAIL[email protected];\
export GIT_COMMITTER_NAME="Commmiter Name";\
export GIT_COMMITTER_EMAIL[email protected];\
git commit-tree "$@"'

Solution 3 - Git

If there are no other authors, you can do:

git filter-branch --commit-filter 'export GIT_AUTHOR_NAME="authorname"; \
export GIT_AUTHOR_EMAIL[email protected]; git commit-tree "$@"'

Solution 4 - Git

Save the script below as e.g. ~/.bin/git-replace-author and run it using, e.g:

git replace-author "John Ssmith" "John Smith" "[email protected]"

With no arguments, it updates all commits with your name to use your current email address according to Git config.

DEFAULT_NAME="$(git config"
DEFAULT_EMAIL="$(git config"
export OLD_NAME="${1:-$DEFAULT_NAME}"
export NEW_NAME="${2:-$DEFAULT_NAME}"

echo "Old:" $OLD_NAME "<*>"
echo "New:" "$NEW_NAME <$NEW_EMAIL>"
echo "To undo, use: git reset $(git rev-parse HEAD)"

git filter-branch --env-filter \
'if [ "$GIT_AUTHOR_NAME" = "${OLD_NAME}" ]; then

Raw (to download)

Solution 5 - Git

Only if you haven't pushed your commits to the world. Other wise everyone else has your old name in their repo which is unlikely you can change everyone's.

Solution 6 - Git

With Git 2.24 (Q4 2019), git filter-branch (and BFG) is deprecated.

The equivalent would be, using newren/git-filter-repo, and its example section:

cd repo
git filter-repo --mailmap my-mailmap

with my-mailmap:

Correct Name <> <>

That would replace the author name and email of any commit done by anyone with <[email protected]>

See git shortlog mapping author section for the exact syntax of


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoshuaView Question on Stackoverflow
Solution 1 - GitJosh LeeView Answer on Stackoverflow
Solution 2 - Gituser11153View Answer on Stackoverflow
Solution 3 - Gitdenis.peplinView Answer on Stackoverflow
Solution 4 - GitZazView Answer on Stackoverflow
Solution 5 - GitEnabrenTaneView Answer on Stackoverflow
Solution 6 - GitVonCView Answer on Stackoverflow