Imagine that you are working on a part of a project and it starts getting messy. There has been an urgent bug that needs your immediate attention. It is time to your changes and switch branches. The problem is, you don’t want to do a commit of a half-done work. The solution is . save git stash Stashing is handy if you need to quickly switch context and work on something else but you’re mid-way through a code change and aren’t quite ready to commit. By Bitbucket Stashing Let’s say you currently have a couple of local modifications. Run , to check your current state: [git status](https://kolosek.com/git-commands-tutorial-part2/) $ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)# modified: index.html# Changes not staged for commit:# (use "git add <file>..." to update what will be committed# modified: assets/stylesheets/styles.css You need to work on that urgent bug. First, you want to save out unfinished work changes without committing them. This is where comes as a savior: git stash $ git stashSaved working directory and index state WIP on master: bb06da6 Modified the index pageHEAD is now at bb06da6 Modified the index page(To restore them type "git stash apply") Your is now clean and all uncommitted local changes have been saved! At this point, you’re free to make new changes, , , and perform any other Git operations. working directory create new commits switch branches By default, stashes are identified as “WIP” — work in progress, on top of the branch and commit they are created from. Re-applying Your Stash is a temporary storage. When you’re ready to continue where you left off, you can restore the saved state easily: . Git stash git stash pop Popping your stash removes the changes from your stash and reapplies the last saved state. If you want to in the stash as well, you can use instead. keep the changes git stash apply Additional Tips and Tricks There are a couple of other things you can do with a stash. Let’s take a look! Save a stash with a : . Saving stashes message $ git stash save <message> Try this out by adding CSS-line high to your styles and stash it with a nice comment. This is the only way to save : or Stashing untracked files untracked files $ git stash -u $ git stash --include-untracked When you or , Git will create a Git commit object with a name and then save it in your repo. You can view the you made at any time! . List multiple stashes git stash git stash save list of stashes $ git stash list $ git stash list[email protected]{0}: On master: Modified the index page[email protected]{1}: WIP on master: bb06da6 Initial Commit You can choose to just a single file, a collection of files, or individual changes from within files: or . Partial stashes stash $ git stash -p $ git stash --patch RSpec tests are a must in the Ruby on Rails projects, but they might not be always complete. Stash only the part that is ready to go! There are two ways to view a stash: to view the of a stash — or view only the - . Viewing stash diffs full diff $ git stash show -p latest stash $ git stash show $ git stash showindex.html | 1 +style.css | 2 ++2 files changed, 3 insertions(+) Create a to apply your stashed changes to, and then pop your stashed changes onto it: . Creating a branch from the stash new branch $ git stash branch <branch_name> <stash_id> This is another way to save your stash before moving on with the project. Use it with caution, it maybe is difficult to revert. The only way to revert it is if you didn’t close the terminal after deleting the stash. If you no longer need a , you can delete it with: . Or you can of your stashes from the repo with: . Remove your stash particular stash $ git stash drop <stash_id> delete all $ git stash clear Hope this article helped you to get a better understanding how stashing works. Be sure to test it out! Originally published at kolosek.com on May 14, 2018.