

Stashing your work with git - gotrunko
http://pierrerambaud.com/blog/linux/2013-06-08-stashing-your-work-with-git

======
artagnon
One place where the stash is really useful is pre-rebase. Unlike in merge, you
need a clean worktree before you can rebase irrespective of whether or not
those worktree changes will be affected by the rebase. A very common workflow
on a topic branch:

    
    
      $ git stash
      $ git rebase master
      $ git stash pop
    

To automate this workflow, there is a topic called rr/rebase-autostash that
introduces the configuration variable rebase.autostash which will
automatically 'stash' and 'stash pop' for you.

The topic is still cooking in git.git, and is due to hit `master` in a few
days. If you want to know more, read about it from the `pu` branch of git.git.
I've put up the most important commit message here [1] for convenience.

[1]: [http://artagnon.com/git-rebase.autostash](http://artagnon.com/git-
rebase.autostash)

------
jnuss
Useful post that taught me a few new tricks about stash.

I like to use stashes as opposed to a "half commit" mentioned by others
because conceptually it's not a commit; it represents a chunk of work that is
not in a commit-ready state, but is a work in progress. You can (and almost
always should, IMHO) include a description of a stash and you also know what
commit the stash is based off on and the branch you had checked out when you
stashed. Thus, you get the same basic information as a "half commit" while
avoiding what for me is a mixing of conceptually different things that I
prefer to keep separate.

Of course, to each their own. That's one of the things I love about git is
that it offers at least some flexibility to taylor it to what you feel is your
optimal workflow.

------
oneandoneis2
stash is something that should be used for only the briefest of times - the
only time I use it is "stash, pull, unstash"

If you want to save partial work to a branch, commit it, go do your work on
the other branch, then use "reset --soft HEAD^" to undo the commit but keep
the work.

Far more reliable

~~~
gbog
Why? I stash often and it has been quite reliable for me.

~~~
oneandoneis2
primarily, if you come back to a stash a week later, other than your memory,
what tells you what branch that stashed code belongs to?

If somebody else needs to take over the project and pulls the branch, what
tells him there's also stashed code for it?

stashes should be very short-lived, they're the wrong tool for anything else

~~~
jnuss
I agree that stashes should be short-lived, but

    
    
      % git stash list
    

will show you what branch was checked out when you stashed. Also, because a
stash is represented as a commit, you can know what commit the stash is based
on. From the git-stash man page:

"A stash is represented as a commit whose tree records the state of the
working directory, and its first parent is the commit at HEAD when the stash
was created. The tree of the second parent records the state of the index when
the stash is made, and it is made a child of the HEAD commit. The ancestry
graph looks like this:

    
    
             .----W
            /    /
      -----H----I
    

where H is the HEAD commit, I is a commit that records the state of the index,
and W is a commit that records the state of the working tree."

------
chimeracoder
git-stash is cool, but it can be easy to fall into a habit of creating stashes
that you never come back to. When you finally list them all, you find 10, 20
stashes, and you can't remember what they all refer to. I find that situation
nightmarish.

I prefer to make a half-commit (and note this), and simply rebase -i later on
( _before_ I push my feature branch).

Then again, I'm very comfortable with rebasing my work and how to avoid issues
when doing so, and I recognize that not everyone is.

~~~
gbog
I have my stashes listed in the status, and drop them when needed. For me
committing requires a good name and needs to be "somewhere", so it is a deeper
action, while I can put any kind of crap in a stash instantly, and drop it if
unused.

