Using git stash
In this example, we explore the git stash
command and learn how we can use it to quickly put away uncommitted changes and retrieve these again. This can be useful when being interrupted with 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 save the state of your current working directory with/without a staging area and restore a clean state of the working tree.
Getting ready
In this example, we'll use the cookbook-tips-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:
$ git clone https://github.com/dvaske/cookbook-tips-tricks.git $ cd cookbook-tips-tricks $ git checkout master
Make some changes to foo
and add them to the staging area:
$ echo "Just another unfinished line" >> foo $ git add foo
Make some changes to bar
and create a new file...