Git Question

What are the real benefits of stash command?

I came across a

command in git and I really don't understand benefits of such command.

Suppose I created some temporary changes in
, and I want to checkout on
. My usual practise is to create commit with
temp commit
message in
, and then perform checkout on
. Then if I want to come back to
, I perform checkout and discard last commit (preserving changes) of
, then I continue to work.

In my opinion,
command is just another way to do such thing.

What are the real benefits of
command? Maybe is it just shortcut for such case?

Answer Source

The stash command can save the current state of the index, the working dir and of untracked files. It's just a lot quicker to run git stash than it is to decide what changes to add to the staging area and commit with a commit message.

Moreover, a stash can be applied in a different position than where it was initially created. You could do that by temporarily commiting on the current branch, switching to a different branch, cherry-picking your commit, and then removing it from where it was originally created.

It's just a quick way of getting a clean working directory if you need to do something else.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download