Sometimes, you may be in the middle of a set of changes that are not yet completed, when you need to stop what you’re doing and work on something else. For example, you might be updating the documentation when a bug report comes in and you want to work on the bug. But you can’t just switch branches, since you haven’t finished your current changes.
The way to work around this problem is with ‘git stash’. This command saves your changes in a special place within Git from which they may be restored later. After executing ‘git stash’, your current branch is restored to its original, pristine state.
The workflow might go something like this:
$ git checkout my-local-branch Checkout a work branch ... Do some work $ git stash Save the work aside $ git checkout gawk-4.1-stable Work on a bug fix ... Now we're done $ git checkout my-local-branch Go back to our local work $ git stash pop Restore the earlier changes
The stash is maintained as a stack. Sets of changes are pushed onto the stack by ‘git stash’ and popped off of it with ‘git stash pop’. You may use ‘git stash list’ to see the list of saved changes.