git command of the day: #10

Author: Jeff Anderson

git stash

This command throws all your working directory changes into a "stash", which can be later re-applied with the git stash apply command. This is nice when you're not ready to commit, but you need to get something else committed too. The example used in the documentation for this command is your big boss comes in and needs an emergency fix for something. Without git stash, the workflow to achieve the same result has more steps and can be more awkward.

So, I got up in the middle of programming working on a small, low priority project several months ago. I came back to it recently, and after reviewing what I had left, I decided I had merged something to my master branch that I didn't really want in place quite yet. I also had some changes in the working directory that hadn't been added to the index. I did a git reset --hard HEAD^ which of course got rid of my working changes.

I had completely forgotten about the git stash command. This command used to find its way into my workflow frequently. In the last several months I haven't been needing it as much. After the fact, I kicked myself for not committing the changes when I wrote them a long time ago, and then for not using git stash.

Posted: Feb 03, 2010 | Tags: git
  • Ozan Onay said at Feb 09, 2010:

    Also useful to note that stash is a stack. Stash multiple times, then git stash pop to apply a stash and remove it from the stack.

Comments are closed.