In Git, the stash
command is used to temporarily save changes that youve made to your working copy so you can work on something else, and then come back and re-apply them. This is useful when you want to switch branches or work on something else without committing half-done work. The stash
command takes the dirty state of your working directory, including modified tracked files and staged changes, and saves it on a stack of unfinished changes that you can reapply at any time, even on a different branch.
When you run git stash
, Git stores all the changes in a stash and resets the state of the workspace to its prior commit state. You can stash several times to create multiple stashes, and then use git stash list
to view them. By default, stashes are identified simply as a "WIP" (work in progress) on top of the branch and commit that you created the stash from. Stashes are actually encoded in your repository as commit objects, and the special ref at .git/refs/stash
points to your most recently created stash.
You can inspect stashes with git stash show
and restore them with git stash apply
. If you just want to drop a stash, you can use git stash drop
. By default, a stash is listed as "WIP on branchname …", but you can give it a more descriptive message with git stash push -m "message"
.