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 ...
Get Git: Mastering Version Control now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.