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
A soft git reset will put committed changes back into your index. Next, checkout the branch you had intended to commit on. Then git commit with a new commit message.
git reset --soft
git checkout
git commit -m "Commit message goes here"
From git docs:
git reset [This form resets the current branch head to and possibly updates the index (resetting it to the tree of ) and the working tree depending on . If is omitted, defaults to --mixed. The must be one of the following:] [ ]
--softDoes not touch the index file or the working tree at all (but resets the head to , just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.