Skip to content

Instantly share code, notes, and snippets.

@mauvehed
Forked from carlosmcevilly/gist:2221249
Last active April 18, 2018 15:46
Show Gist options
  • Save mauvehed/6a06eab671c0a2aeca1979154ac19a16 to your computer and use it in GitHub Desktop.
Save mauvehed/6a06eab671c0a2aeca1979154ac19a16 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"
$ 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.
6. verify your email was changed in the git log
$ git log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment