Git: Stash changes

Stashing your work

If you ever need to put uncommitted changes out of the way, there is a quick command for it:

Making a stash:
git stash save  "some custom message"

Or just:

Quickly stashing changes:
git stash

Now the working tree is clean again! And you're free to work on something else. For example a different feature, or an emergency fix.

Restoring stashed changes

Previously stashed changes can be restored by running:

Restoring a stash:
git stash pop

The git stash save command can be run multiple times, making a stack of stashed changes. Removing happens with git stash pop because it takes one stashed set from the stack.

Exploring stashes

The list of stashed changes can be managed with these commands:

Stash commands:
git stash list               # show a list of all stashes
git stash show               # show the last stash
git stash show stash@{1}      # show the previous stash

git stash apply              # apply the stash only, don't delete it
git stash drop               # drop the last stash
git stash drop stash@{1}      # drop a previous stash


To improve the merging of branches, Git offers the rebase command.

blog comments powered by Disqus