Chapter 10. The Stash and the Reflog

Do you ever feel overwhelmed in your daily development cycle when the constant interruptions, demands for bug fixes, and requests from coworkers or managers all pile up and clutter the real work you are trying to do? If so, the stash was designed to help you!

In this chapter you will learn how the stash works and how to view the stashed context. Following this, you will learn about the reflog, which records the Git repository’s local commits. These features will help you leverage the options Git provides when you need to temporarily stash your current work in order to work on something else.

The Stash

The stash is a mechanism for capturing your work in progress, allowing you to save it and return to it at a more convenient time. Sure, you can already do that using Git’s existing branch and commit mechanisms, but the stash lets you quickly capture your entire index and working directory with one simple command, leaving your repository clean, uncluttered, and ready for an alternate development direction. Another single command restores the index and the working directory, allowing you to your resume where you left off.

Let’s explore how the stash works with some example use cases.

Use Case: Interrupted Workflow

In this scenario, you are happily working in your Git repository and have changed several files and maybe even staged a few in the index. Then you’re interrupted. Perhaps a critical bug has been discovered, and you’ve been ...

Get Version Control with Git, 3rd Edition 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.