TurnKey Linux Virtual Appliance Library

Use the stash, Luke (git-stash)

I was in the middle of developing a new feature for the TurnKey Hub when I received a bug report that needed to be fixed.

What to do? Throw away my current changes? Checkout a clean branch? Of course not! Just stash my changes away, fix the bug, and get my changes back so I can continue development.

It's so simple and useful, I thought I'd share my notes in case others don't know about git-stash.

git-status      # we have a bunch of uncommitted changes
git-stash       # stashes away changes, reverts working copy to HEAD
git-status      # no uncommitted changes

... fix the bug

git-stash list  # see what we have stashed away
git-stash pop   # apply uncommitted changes back to working copy

The above makes simple use of the Git stash, but there is lots more you can do with it. Also remember that the stash acts like a stack which means you can store multiple stashes.

You can get future posts delivered by email or good old-fashioned RSS.
TurnKey also has a presence on Google+, Twitter and Facebook.

Comments

git-xxx

Hi Alon,

Git has this wonderful ability to look for commands in your path named git-* and let you run them as "git *" instead. For instance, I use the "Git Extras" at git://github.com/visionmedia/git-extras.git [see https://github.com/visionmedia/git-extras#readme for documentation] and since they're in my path, they just work.

I just wanted to say that when you are showing example git commands, generally you would say "git stash" rather than "git-stash".

Reid

Feature Branches

I prefer to work in feature branches and make temporal commits. Because "git stash" doesn't save the untracked files.


So, my work flow is:
    * Work in Feature Branch A
    * New Hot bug appear
    * Make a temporal commit in Feature Branch A
    * Create Hot Bugfix Branch B. Fix the bug. Merge Hot Bugfix Branch B, and push the changes.
    * Move to the Feature Branch A
    * reset to HEAD^ and continue working
    * When it's done, Merge the Feature Branch A, and push the changes

All the merge are done with no fast forward (git merge --no-ff)

Thanks,
juan.

git stash

Juan, instead of temporary comit + reset HEAD^, I just use stash.

# working on branch "master"
git stash
git checkout -b hotfix
# fix the bug
git commit -a
git checkout master
git merge hotfix
git stash apply
# or "git stash pop" if you are confident

Doesn't that make sense?

stash rocks

git stash --include-untracked

Brilliant use of stash...

The stash use is brilliant.   reset HEAD is nice too.  Thanks!

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)