Fueling the Web

Git Stash

I often have situations where I have modified files that I need to set aside but not lose completely. Maybe I need to work on something else, or I want to merge/rebase my develop branch before continuing.

Git Stash is just the command to use for this.

The simplest workflow is to run git stash to store your changes and then git stash pop when you're ready to bring your changes back.

Here are some additional stash commands I like to use:

  • git stash list: Display a list of all of your stashes. These are ordered with the most recent stashes at the top.
  • git stash show @stashId: List modified files for the given stash.
  • git stash show @stashId -p: Show the diffs for the modified files in the given stash.
  • git stash apply @stashId: Apply the given stash.
  • git stash drop @stashId: Drop the given stash.
  • git stash save 'Message Here': Save a stash with a custom message.
  • git stash -u: Stash both modifed and untracked files.
  • git stash clear: Remove all saved stashes.

Note: Replace @stashId in the above commands with a valid stash id such as stash@{0}. Stash ids can be found when you run git stash list.

What Git Stash commands do you like to use?