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 conflict, 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 (though you can also stash untracked files with the --include-untracked
option), and the state of the staging area, then 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.
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 for the interruption to last long, you can simply...