Using git stash
In this example, we'll explore the git stash
command and learn how we can use it to quickly stash
away uncommitted changes and retrieve them again. This can be useful when you are interrupted while doing an urgent task and you are not yet ready to commit the work you currently have in your working directory. With the git stash
command, you can save the state of your current working directory with/without a staging area and restore the working tree to a clean state.
Getting ready
In this example, we'll use the Git-Version-Control-Cookbook-Second-Edition_tips_and_tricks
 repository. We'll use the master
branch, but before we are ready to try the stash
command, we need to create some changes in the working directory and the staging area, as follows:
$ git clone https://github.com/PacktPublishing/Git-Version-Control-Cookbook-Second-Edition_tips_and_tricks.git $ cd Git-Version-Control-Cookbook-Second-Edition_tips_and_tricks $ git checkout master
Make some changes to foo
and add them...