Become a Git Contortionist With Stash

Annie the ContortionistOne of the great aspects of the Git source control system is its flexibility. Almost any sticky situation you may encounter as a developer working with source control can be solved with Git.

Take this scenario, you’re halfway through writing a class for a new feature when you get a call.. the client has found a show stopping bug in the application and it needs to be fixed right away. To be able to fix the bug you will need to switch onto the live code branch but you can’t go switching branches with a load of uncommitted changes. Now you don’t want to commit your code as its half done and won’t even compile right now, but you don’t want to lose the changes either… git stash to the rescue!

When you issue the git stash command all your changes will be committed to a stack. Leaving you with no changes on your current working branch and free to branch where ever you want. So now you can switch to the live branch and do your bug fixing work. Once that is done you can simply move back to the feature branch and apply the stashed changes. Hey presto, you are back where you started with your uncommitted half complete work!

If you really get into lots of parallel work you can stash multiple times, just be sure to remember that it is a stack and your last changes you have stashed will come back off stack first.

Comments

Copyright © 2016 - Hook Technologies Ltd - Powered by Octopress