The git stash command is for "stashing" your changes in order to work on something else, then you can come back to the stashed changes later.
| Command | Abbreviated | Description |
|---|---|---|
git stash |
same as git stash push |
|
git stash push |
this will “stash” the WIP for a branch and go back to HEAD | |
git stash push --keep-index |
this stashes only the un-staged, modified files | |
git stash push --include-untracked |
-u |
this stashes untracked files as well as other files |
git stash push --message “A descriptive message” |
-m |
helpful so you know what it was about |
git stash list |
shows branch and commit before stashing | |
git stash list --stat |
as plain “list” but with change details | |
git stash show |
details on stashed changes | |
git stash pop |
get the WIP back out, actually same as git stash apply followed by git stash drop |
|
git stash apply |
apply the stashed changes but also leave them on the list | |
git stash drop |
remove the stash at the top of the list | |
git stash branch new-branch |
put stashed changed on a new branch, handy if you deleted the branch they were stashed from |
Whilst you have changes stashed you can switch branches, to do whatever other changes you need. When you "pop" a stash you might have a merge issue. In this case it will not actually get "popped" off so you will need to drop it manually. It is always good to check what is going on with git stash list to be clear what is happening.
When you have multiple groups of changes stashed they will all be shown on the list, or in other words every time you push changes a new group of changes is added to the list. With most of the above commands you can specify a stash name, for example git stash show stash@{0}.
Note that when using git stash branch you will then need to merge this branch, it necessary.
See also: