Stashing away your changes
Often, when you’ve been working on a project, and things are in a messy state not suitable for a permanent commit, you want to temporarily save the current state and go to work on something else. The answer to this problem is the git
stash
command.
Stashing takes the dirty state of your working area – that is, your modified tracked files in your worktree and the state of the staging area – saves this state, and resets both the working directory and the index to the last committed version (to match the HEAD
commit), effectively running git reset --hard HEAD
. You can then reapply the stashed changes at any time.
You can also stash untracked files with the --
include-untracked
option.
Stashes are saved on a stack: by default, you apply the last stashed changes (stash@{0}
), though you can list stashed changes (with git stash list
) and explicitly select any of the stashes.
Using git stash
If you don’t expect the interruption...