Git 1.5.3 : stash

I installed this monday Git 1.5.3 and discovered a new functionality I find worth sharing : stash.

Basically, stash grab your current uncommitted changes and put them away until you want to reapply them. Git documentation for git-stash lists two examples where this comes in handy :

  1. Pulling into a dirty tree
I’m sure you already had the nightmare it is that you started working on a new functionality when a change you need appears in the upstream repository. Your current changes conflicting with the upstream’s ones git pull does not work. Here come the stash, simply issue a git stash (or git-stash, with an optional description message as you can have multiple stashes), then git pull to include the upstream changes and finally git stash apply to re-integrate your latest stashed modifications.
  1. Interrupted workflow (this one talk to me so much)
You’re working hard on some new kick-ass features when someone (your boss / client) come in and want this immediate fix in what it call a critical bug. One solution is to commit your changes to a new branch, correct the fix, commit it, rebase the new branch to the head with the fix, and then merge back the changes. I’m sure you already see the power of stash in such cases. No more in a hurry branches and commits, simply stash your changes, correct the bug, and reapply the stashed changes.

Tue, 04 Sep 2007 16:57 Posted in

Comment Git 1.5.3 : stash