Failed to branch? Fix it fast!

Brian Dart
IHME Tech
Published in
1 min readFeb 21, 2018
Photo credit- https://unsplash.com/@lukaszlada

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:

  1. git stash
  2. git checkout -b my-new-branch-name
  3. 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.

--

--

Brian Dart
IHME Tech

Assistant Director — Visualizations and Web Development @ IHME in Seattle, WA