public
Last active

fix git commit with wrong email address in git config, before pushing

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
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.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.