Skip to content

Instantly share code, notes, and snippets.

@bgromov
Created June 23, 2016 17:50
Show Gist options
  • Select an option

  • Save bgromov/a1905055a8b9cdbeb1d2a87e70920cc8 to your computer and use it in GitHub Desktop.

Select an option

Save bgromov/a1905055a8b9cdbeb1d2a87e70920cc8 to your computer and use it in GitHub Desktop.
Git: reset author for ALL commits
#!/bin/sh
# Credits: http://stackoverflow.com/a/750191
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='Newname'
GIT_AUTHOR_EMAIL='new@email'
GIT_COMMITTER_NAME='Newname'
GIT_COMMITTER_EMAIL='new@email'
" HEAD
@ucalyptus

Copy link
Copy Markdown

@bgromov , Newname is our github id or actual name?

@benitezandres

Copy link
Copy Markdown

Thanks!

@sebastian13

Copy link
Copy Markdown

Nice! This even keeps old timestamps!
To push to a remote afterwards, a --force is needed.

git push --force --tags origin 'refs/heads/main'
# or
git push --force

Credits to the comments of https://stackoverflow.com/a/750191/8940679

@artiscode

Copy link
Copy Markdown

Thank you so much! This really helps when you change from a personal handle to a business one.

@Yaroslavzev

Copy link
Copy Markdown

Thank you so much!

@aitechcompany

Copy link
Copy Markdown

Thank you

@biniama

biniama commented Sep 17, 2021

Copy link
Copy Markdown

Thanks! I get this warning though.

WARNING: git-filter-branch has a glut of gotchas generating mangled history
         rewrites.  Hit Ctrl-C before proceeding to abort, then use an
         alternative filtering tool such as 'git filter-repo'
         (https://github.com/newren/git-filter-repo/) instead.  See the
         filter-branch manual page for more details; to squelch this warning,
         set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...

Rewrite 2a51e47ec68d9fb91xxxxxxxx (2/2) (0 seconds passed, remaining 0 predicted)    
WARNING: Ref 'refs/heads/main' is unchanged

Can you suggest something?

@arturkowalczyk300

Copy link
Copy Markdown

Thanks, works brillant.

@BeytullahC

Copy link
Copy Markdown

Thanks :)

@tt1k

tt1k commented Mar 2, 2022

Copy link
Copy Markdown

Thanks :)

@anydev1103

Copy link
Copy Markdown

thanks

@raymond-le-goldenowl

Copy link
Copy Markdown

thanks

@jun-uen0

jun-uen0 commented May 4, 2022

Copy link
Copy Markdown

Thanks a lot!

@billmetangmo

Copy link
Copy Markdown

Thanks. To update only your commits and not all ( even if not yours):

#!/bin/sh

git filter-branch -f --env-filter '
OLD_EMAIL="xxxxxxxxxxxxxxxxxxxxxxxxxx"
CORRECT_NAME="zzzzzzzzzzzzzzzzz"
CORRECT_EMAIL="yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
'  HEAD

ghost commented Nov 14, 2022

Copy link
Copy Markdown

Thank you so much!

@Irfanwani

Copy link
Copy Markdown

Thank you very much

@KaduUlson

Copy link
Copy Markdown

Awesome! Thank you

@miorelli

miorelli commented Feb 7, 2023

Copy link
Copy Markdown

Thanks a lot.

@PipaStanislav

Copy link
Copy Markdown

Thanks

@INVISIBLE5130

Copy link
Copy Markdown

Thank you a lot!

@souravCoder1

Copy link
Copy Markdown

@bgromov , Newname is our github id or actual name?

both will work.

@smac89

smac89 commented May 6, 2024

Copy link
Copy Markdown

@biniama

git filter-repo solution:

git filter-repo --preserve-commit-hashes --name-callback "$(cat <<'EOF'
return b'<replace everything between the quotes with your name>'
EOF
)" --email-callback "$(cat <<'EOF'
return b'<replace everything between the quotes with your email>'
EOF
)"

If you had signed your commits before this, note that the above command will remove those signatures. For me, this answer was useful to resign all commits without loosing commit dates.

@snimavat

Copy link
Copy Markdown

Works good, except merge commits, where it still shows the another user

@jbcr

jbcr commented Oct 28, 2024

Copy link
Copy Markdown

Work fine. Thank you.

@brightdev124

Copy link
Copy Markdown

Good, really be helpful!

@amosshi

amosshi commented Jun 17, 2025

Copy link
Copy Markdown

We love this script, thank you 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment