Git Stash - How To Save Your Changes Temporarily
Maybe your like
There are lots of situations where a clean working copy is recommended or even required: when merging branches, when pulling from a remote, or simply when checking out a different branch.
The "git stash" command can help you to (temporarily but safely) store your uncommitted local changes - and leave you with a clean working copy.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Download Now for Freegit stash: a Clipboard for Your Changes
Let's say you currently have a couple of local modifications:
$ git status modified: index.php modified: css/styles.cssIf you have to switch context - e.g. because you need to work on an urgent bug - you need to get these changes out of the way. You shouldn't just commit them, of course, because it's unfinished work.
This is where "git stash" comes in handy:
$ git stash Saved working directory and index state WIP on master: 2dfe283 Implement the new login box HEAD is now at 2dfe283 Implement the new login boxYour working copy is now clean: all uncommitted local changes have been saved on this kind of "clipboard" that Git's Stash represents. You're ready to start your new task (for example by pulling changes from remote or simply switching branches).
Continuing Where You Left Off with git stash pop
As already mentioned, Git's Stash is meant as a temporary storage. When you're ready to continue where you left off, you can restore the saved state easily:
$ git stash popThe "pop" flag will reapply the last saved state and, at the same time, delete its representation on the Stash (in other words: it does the clean-up for you).
In case you want to apply a specific Stash item (not the most recent one), you can provide the index name of that item in the "pop" option:
$ git stash pop stash@{2}Tip
Using the Stash in Tower
In case you are using the Tower Git client, saving to and restoring from the Stash can be performed right from the toolbar. Tower even lets you restore the exact state of your Working Copy when you restore a Stash:
Learn More
- Check out the chapter Saving Changes Temporarily in our free online book
Related Questions
- Using "git stash list" to view all your stash entries
- How to use "git bisect" to quickly find bugs
- What is Continuous Integration (CI)?
- What are Git hooks?
- What is the Git Reflog?
- How to Set Up Git Aliases
- Git Filter-Repo: The Best Way to Rewrite Git History
- Git Rev-Parse: Your Swiss Army Knife for Git References
- Git Fast-Forward: How and When to Use it
- Using Git Credential Manager for Effortless Authentication
- Understanding "git blame"
For additional Git-related questions (and answers!), visit our FAQ homepage.
Tag » How To Change Branch In Git Without Commit
-
Git: Switch Branch And Ignore Any Changes Without Committing
-
How To Change The Branch Without Committing So That I Can ... - Reddit
-
Git (revision Control): If You Do Not Commit And You Switch Branches ...
-
Move Existing, Uncommitted Work To A New Branch In Git | Baeldung
-
Git Switch Branch – How To Change The Branch In Git - FreeCodeCamp
-
Git - Git-checkout Documentation
-
Git: Switch Branch And Ignore Any Changes Without Committing
-
Switching Branch Without Commit In Working Directory - DQ Courses
-
How To Switch Branch On Git - Devconnected
-
Learn Git Collaboration - Nulab
-
Using Git Switch To Change Branches - Tempertemper
-
Stashing Changes - GitHub Docs
-
Git Stash: Save Local Changes Without Commit In Git - Fedingo
-
Create A New Git Branch With Current Local Changes Saved By Example