Archive

Archive for the ‘Git’ Category

Stashing Git

January 21st, 2009

With any application, it’s tempting to learn only the commands you need for your daily tasks. The danger is that oftentimes, you miss one. You end up going the long way around a problem when there’s been a shortcut in existence all along.

I just learned a new git command (thank you, Michael Ivey) - git stash.

Some Background
On my primary Rails project, I’m the sole developer. Most times, I work from the master branch, but occasionally I’m working on a large feature that might take a week or more to complete. During those times, I want to maintain access to the master branch in case any bugs arise. So typically, I create a branch for the new feature and merge it in when the feature is complete.

Stashing
Stashing allows you to essentially put your most recent, uncommitted changes on hold while you make a small fix.

$ git stash => saves current changes for a later date
Make small fixes, commit, push, deploy, etc.
$ git stash apply => restore changes from saved state

Who knows if I’ll use this feature for anything more than the occasional quick fix, but it’s a good one to know about. Creating a branch for larger features still makes sense…mostly because I will do several commits to that branch before merging it back.

I don’t know how I would feel about doing EVERYTHING in the master branch, but this is a neat trick to have in my back pocket.

Git