Skip to main content
In this guide, you’ll learn how to use Git stash to temporarily save modifications from your working area. This allows you to switch contexts quickly without committing incomplete work. Imagine you’re working on the third story on the sarah branch when a colleague notices a typo in the first story on the master branch that needs immediate fixing. Rather than committing your unfinished work, you can quickly stash your changes, leaving a clean working area for the urgent fix.
Git stash is especially useful when working with multiple features or hotfixes. It helps maintain a clean working directory while switching between tasks.

Basic Stashing Commands

To stash all modifications in your working directory, run:
This command saves your changes in a stack-like structure, similar to stacking books. When you’re ready to continue working on the third story, you can retrieve the most recent stash with:
As you keep working, you might add more changes to your stash, which will accumulate over time. To view all stored stashes, use:
For example, you might see output like:

Inspecting and Restoring Specific Stashes

If you want to inspect the contents of a specific stash, use the git stash show command followed by the stash identifier:
To restore a specific stash instead of the most recent one, simply specify its identifier with the pop command:
Always verify your current branch before applying a stash to avoid merging changes into the wrong context.

Conclusion

This guide has provided an overview of how to use Git stash to manage your work-in-progress changes. Practice these commands regularly to gain confidence and streamline your Git workflow. For more information on Git and version control best practices, check out the Git Documentation.

Watch Video

Practice Lab