When and why would you use git stash?

Experience Level: Mid-level
Tags: Git


The command git stash is used for stashing away changes from git workspace to temporary storage (stash).

Watch the video Git stash - what it is and when to use it where we explain everything.

When you run git stash without any additional parameters, it does the same as git stash push

(the push parameter is used by default).

You usually use git stash when you work on something in your workspace and someone else needs you to skip to something else (critical bug or anything else that deserves attention). If you don't have all the changes finished yet, you shouldn't commit the incomplete changes to the repository. In such case you, you should store your changes to the stash temporarily (which will clean up your workspace), then you can fix the bug and once you are finished with it, you can again restore the original changes from stash using git pop command. 

Related Git job interview questions