I bet the following has happened to you: you are happily working on a project and are in the middle of something. You are not ready to commit your changes, because you your tests don’t pass yet. Then your client calls with a bug report that needs to be fixed right now. (You know how clients can be.)
So, what do you do? Throw away your current changes to make the patch? Checkout a clean copy of your project to make the changes? No! You just stash your changes away, and make the patch! Afterward you grab your changes back and continue work.
Git features The Stash, which is as much as a good place to store uncommitted changes. When you stash you changes, the will be stored, and your working copy will be reverted to HEAD (the last commit revision) of your code.
When you restore your stash, you changes are reapplied and you continue working on your code.
Stash your current changes
$ git stash save <message for later reference> Saved "WIP on master: e71813e..."
List current stashes
Yes, you can have more than one!! The stash works like a stack. Every time you save a new stash, it’s put on top of the stack.
$ git stash list
stash@{0}: WIP on master: e71813e..."Note the stash@{0} part? That’s your stash ID, you’ll need it to restore it later on. Let’s do that right now. The stash ID changes with every stash you make. stash@{0} refers to the last stash you made.
Apply a stash
$ git stash apply stash@{0}You may notice the stash is still there after you have applied it. You can drop it if you don’t need it any more.
$ git stash drop stash@{0}Or, because the stash acts like a stack, you can pop off the last stash you saved:
$ git stash pop
If you want to wipe all your stashes away, run the ‘clear’ command:
$ git stash clear
It may very well be that you don’t use stashes that often. If you just want to quickly stash your changes to restore them later, you can leave out the stash ID.
$ git stash ... $ git stash pop
Feel free to experiment with the stash before using it on some really important work.
Please leave a comment if you like this article, and would like to see more Git related stuff here on Ariejan.net.

[...] on how to use Git with a Subversion repository to get some of the Git goodness, local branches, stashes and much more, without having to persuade everyone else on your project to migrate to [...]
[...] can use Git with a Subversion repository to get some of the Git goodness, local branches, stashes and much more, without having to persuade everyone else on your project to migrate to [...]
This is not quite right. All the examples with “0″ used to identify a stash should use the name “stash@{0}”. Unfortunately, these examples will work, but only because git stash has the broken behavior that if it doesn’t recognize a stash name, it applies the command to “stash@{0}” by default. That means that if you use “1″ instead of “0″ in those examples, you will apply, drop or pop the top stash, “stash@{0}”, even though you really wanted to do that to the second stashed state from the top. Not good! There’s been talk on the git mailing list about fixing this broken behavior, but I don’t believe it’s fixed as of the 1.6.0.2 version of git.
Thanks for this, I only ever use git stash quickly to stash my changes whilst I change branch (when I realise I’m working on the wrong branch locally!) and remembering to clear the stash after applying it everytime was driving me nuts.
I now know I can git stash pop it instead, which does the cleanup for me, cheers!
[...] on top of the incremental backup. Right now I’m eyeing git for ideas because it has features like stash and bisect. I’m also considering adding on a continuous backup system (like Norton GoBack or [...]
[...] using the #git stash http://ariejan.net/2008/04/23/git-using-the-stash/ [...]
[...] git stash: http://ariejan.net/2008/04/23/git-using-the-stash/ [...]
[...] git stash: http://ariejan.net/2008/04/23/git-using-the-stash/ [...]