This often happens to me: I write some code, go to check in my changes, and then realize I\'m not in the proper branch to check in those changes. However I can\'t switch to
git stash
is your friend.
If you have not made the commit yet, just run git stash
. This will save away all of your changes.
Switch to the branch you want the changes on and run git stash pop
.
There are lots of uses for git stash. This is certainly one of the more useful reasons.
An example:
# work on some code
git stash
git checkout correct-branch
git stash pop