I'm having a hard time understanding why anyone would ever use git stash
when it seems to be an inferior option.
As far as I can tell, git stash
's use case is to save work in progress that you have on a branch when you go work on another branch.
Usually, when I am in this situation, I run this instead:
$ git add --all
$ git commit -m "WIP: some info about the changes"
and go work on the other branch. When I come back to the branch I was working on, I can simply run git reset HEAD~1
to go back to my previous commit and resume where I was, or stack WIP commits until I'm done and I squash them.
Compared to using git stash
, this seems to me like the superior option:
- I can always run
git pull --rebase
to update my branch and rebase my WIP on top - I can cherry-pick my WIP on another branch if necessary
If I want to, I can even run git checkout -b temporary_branch
before creating my commit so that it is located in a temporary branch instead of the one I was working on:
- this gives me the usual benefits of branches, i.e. I can have several WIP in parallel
- this is also reassuring because it's easier to lose stashed changes than committed changes; if my company's policy allows it (it does), I can even push the temporary branch to ensure I can't lose my changes even if something happens to my computer (while you can't push a stash)
Because of all that, I currently see absolutely no reason to ever use git stash
.
So... what am I missing? I assume the people making git wouldn't include such a command if you could already do everything rather simply without it