Down the rabbit hole

Show me a developer who never goes down the rabbit hole, and I'll show you a quiche-eater. Yes, it's important to be disciplined and not get constantly lost in depth-first-search coding, but... it's also important to have fun from time-to-time.

One thing I love about git is its support for going down the rabbit hole. You're working on trunk, having fun, writing up a mess of code, and then you realize, gee, it would be Good to checkin, and start climbing out of the hole... but it would be Bad to commit to my trunk, and my working directory is dirty. git stash to the rescue:

cat > ~/bin/rabbit_hole.sh
git stash
git checkout -b $1
git stash apply

git stash essentially creates a private, temporary branch of your dirty working directory, and then resets your working directory. Once this is done, you can create a new branch that's clean, and then use git stash to apply your changes back to the working directory. Now you can commit to the side-branch and work your way out of the hole.

The one danger with git stash that I've run into is if you do not apply your changes, you can build up a long stack of old crap. So, don't do that.

No comments:

Post a Comment