Or little computing tricks and hacks
Git: changes in the wrong branch
March 2, 2015Posted by on
As I was happily following instructions to use the puma gem in heroku, I noticed I was on the wrong branch… &*$%= (or word of your choice).
Searches told me to simply go back to my branch (from refactor_home to master) and changes would follow:
git checkout master
but instead I got this mistake:
error: Your local changes to the following files would be overwritten by checkout:
Please, commit your changes or stash them before you can switch branches.
Uhmm. Reading the error message, commit was out of the question. There was “stash” left.
git stash saves the changes somewhere. I ran
and the output was
Saved working directory and index state WIP on refactor_home: 8158613 Refactor finished with fallback for articles only
Then I checked out to the master branch, and ran
git stash pop
and presto. Now pending changes are part of the master branch.
This only worked because both branches were clean. I do not want to adventure what would happen if there were a lot of other changes.
If you want to throw away changes (taken from here):
git reset --hard
git reset --hard HEAD
This post explains what to do if the changes are already committed.