Git - Recovering from accidental commits to master
Suppose you have just committed something in your local repository and now want to push it to the projects master tree. So you give the push command but the result is following :(
! [rejected] master -> master (non-fast forward)
For a while, the easiest solution what I used was to just delete the repository and clone it again. (I was able to do this is easily when I occasionaly push translation updates for GNOME projects.) But eventually I ran into this problem also with my other code projects, so I needed a better solution.
Now, lets assume you have just accidentally committed into your master branch.
git checkout -b bad-master
git branch -D master
git checkout -b master --track origin/master
Vóila - you are back in action :)