ProgFu

programming tips & tricks

Feb 3

Stash it with Git!

How often do you change something and one minute later it breaks and you want to go back to the working version to debug it or just run it again to see how it works.

But what do you do with all those changes you already made? Since something isn’t working, you probably haven’t commited anything to the repository yet.

Hide it in your Secret Stash

You can actually go back without commiting anything to the repository, and that’s thanks to the stash functionality. It basically creates a micro-branch with your current changes.

All you need to do is just run this one small command and all the current changes get stashed away.

git stash

The effect is the same as if you did

git reset --hard HEAD

but your changes are not thrown away, they’re just somewhere else.

Then after you’re done doing what needed to be done, all you need to do is to just reapply those changes

git stash apply

And you’ve got everything back.

Fatal Bug Scenario

Another scenario where this is very useful is if you’re working on a feature, and suddenly, for any reason, you have to go fix a high priority bug, or just take a look at something else and play with it a little bit.

With git stash, you don’t have to worry about where to put your current working changes, like copying the repository and reseting one copy to fix the bug, and then merging it back together

Stashing your changes allows you to do this in a very fast and convenient way.


  1. progfu posted this
Page 1 of 1