Skip to content

Instantly share code, notes, and snippets.

@carlosmcevilly
Last active July 1, 2026 13:41
Show Gist options
  • Select an option

  • Save carlosmcevilly/2221249 to your computer and use it in GitHub Desktop.

Select an option

Save carlosmcevilly/2221249 to your computer and use it in GitHub Desktop.
fix git commit with wrong email address in git config, before pushing
If:
- you add and commit with the wrong email address in git, and
- your remote has a hook set up to prevent you from pushing with the bad address
Then you need to amend the author of your commit before push can succeed:
1. fix your email address in git config:
$ git config user.name "Your Name"
$ git config user.email "your@address.com"
# only do this next line if using submodules... not super common and you would probably know if you were using them
$ git submodule foreach --recursive 'git config user.name "Your Name" && git config user.email "your@address.com"'
2. then do a rebase:
$ git rebase -i HEAD~1
# git brings up your editor.
3. in the editor, mark the commit as 'edit' then save and exit the editor
4. do an amend that resets the author now that your address is changed:
$ git commit --amend --reset-author
5. finish with a rebase:
$ git rebase --continue
# git says:
# Successfully rebased and updated refs/heads/master.
@tbonfim

tbonfim commented Feb 24, 2016

Copy link
Copy Markdown

Yeah Andela, it will work for you

@MrBoog

MrBoog commented May 5, 2017

Copy link
Copy Markdown

Ah. Cool! That's what I need. :)
I guess this line is the point git commit --amend --reset-author

@aditya2337

Copy link
Copy Markdown

Nice explanation, thanks a tonnn!

@chedadsp

chedadsp commented Jan 3, 2018

Copy link
Copy Markdown

What if after pushing successfully, you found out it was wrong email, how do I lik it back? Would the above description also work for it?
Thanks

Yes, it would if you have push --force privilege. Just do everything stated above and than do git push --force.

@coolpalani

Copy link
Copy Markdown

Thanks

@hankliu5

Copy link
Copy Markdown

Appreciate for saving my life ❤️

@MTammvee

Copy link
Copy Markdown

Thank You ! 👼

@ethanrweber

Copy link
Copy Markdown

thanks, this was exactly what I needed lol

@4m1z

4m1z commented Apr 9, 2024

Copy link
Copy Markdown

Thanks 👍

@jalius

jalius commented Nov 29, 2024

Copy link
Copy Markdown

Thanks for this! Please note, when you issue git commit --amend --reset-author, you can add the --no-edit flag to keep the old commit message:
git commit --amend --reset-author --no-edit
You can also chain it with continue if you had multiple commits:
git commit --amend --reset-author --no-edit && git rebase --continue

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