I Forgot to make a Git branch!

programming, version control 1 Comment

One of the great things about GIT is the ease of branching locally. So it is a great idea to branch for each bug fix and feature and then merge those into master when they are fully tested and ready. But what if you get a bug report and go to town on it realizing midway  through that you are working on Master?

Enter GIT Stash

Git Stash will move your un committed changes to a special place and revert the branch back to it’s last commit. So before committing your work, you can do this:

  • git stash
  • git branch branch-name
  • git checkout branch-name
  • git stash pop

Git Stash Pop will grab the last stash and bring it into the current branch. You can now commit to the branch, test and then merge to master when you are ready.

There may be better ways but I do this, feel free to comment below.

Related Posts

1 Comment

  • Author
    Shane on September 25, 2018

    LOL, this is old. git checkout -b is a much better way to handle this.

Leave a Reply

Your email address will not be published. Required fields are marked *