Friday, September 9, 2011

git edit commit message and push to github

Steps to edit a git commit message and also have it show up to Githb:

1. To edit your last commit message:

git commit --amend

2. Edit your commit message on top. If you're using vim, to save and quit, do esc+":wq"

3. Push to Github:

git push --force


Note that if you don't have the "--force", you'll get this error message:

$ git push
To git@github.com:your/repo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:your/repo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
So remember to git push --force!

2 comments:

  1. With great power comes great responsibility.

    ReplyDelete
  2. Exactly what I was looking for. Thanks!

    ReplyDelete