Failed to branch? Fix it fast!
Regardless of your preferred workflow in Git, chances are that you have failed to create a new branch before starting to code some new functionality. Before you hard reset your project and have to redo your work, know that ‘git stash’ can save your bacon.
If you have been working on your code and come to the realization that you are still on the master branch (or another branch where you don’t want to be), have no fear, simply:
git stash
git checkout -b my-new-branch-name
git stash apply
All of the uncommitted changes you had made in the original, incorrect branch will be stashed away on your local machine, allowing you to create a new branch and apply the previously stashed changes there. Easy!
More info on git stash
can be found here.