Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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"
$ 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.
@mentrie

This comment has been minimized.

Show comment Hide comment
@mentrie

mentrie Dec 13, 2015

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

mentrie commented Dec 13, 2015

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

@tbonfim

This comment has been minimized.

Show comment Hide comment
@tbonfim

tbonfim Feb 24, 2016

Yeah Andela, it will work for you

tbonfim commented Feb 24, 2016

Yeah Andela, it will work for you

@MrBoog

This comment has been minimized.

Show comment Hide comment
@MrBoog

MrBoog May 5, 2017

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

MrBoog commented May 5, 2017

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

@aditya2337

This comment has been minimized.

Show comment Hide comment
@aditya2337

aditya2337 May 14, 2017

Nice explanation, thanks a tonnn!

Nice explanation, thanks a tonnn!

@chedadsp

This comment has been minimized.

Show comment Hide comment
@chedadsp

chedadsp Jan 3, 2018

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.

chedadsp commented Jan 3, 2018

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

This comment has been minimized.

Show comment Hide comment
@coolpalani

coolpalani Jan 28, 2018

Thanks

Thanks

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