git stash temporarily shelves (stashes) uncommitted changes so you can switch context — fix a bug, pull updates, or review another branch — and then come back and reapply your work. It is the cleanest way to handle mid-work interruptions without creating WIP commits.
GitStashVersion ControlCLIgit stash
git stash push -u to include them.git stash push -m "WIP: add user auth middleware"
-m flag adds a description to the stash entry. This makes it much easier to identify specific stashes when you have multiple saved. Always add messages when you expect to have the stash for more than a few minutes.git stash push -u
-u (or --include-untracked) flag also stashes new files that aren't yet tracked by git. Without this flag, untracked files stay in your working directory even after stashing.git stash list
stash@{0}: On branch: message. Use this to find the index of a specific stash before applying it.git stash pop
git stash apply stash@{2}
apply restores the stash but keeps the entry in the stash list, unlike pop. Specify a stash index from git stash list. Useful when you want to apply the same stash to multiple branches.git stash show -p stash@{0}
-p flag shows the full diff of the stash. Without it, only a summary of changed files is shown. Use this to review what is in a stash before applying it, especially if you have multiple stashes with similar messages.git stash branch feature/my-work stash@{0}
git stash drop stash@{1}
git stash show -p stash@{1} before dropping to make sure you don't need the changes.git stash clear
git stash list before clearing.git stash to save current changes and get a clean working directory.git stash pop to restore your changes and remove the stash entry.git stash push -m "message" to add a descriptive label when stashing.git stash list to see all saved stashes and manage them.git stash pop applies the stash and removes it from the stash list in one step. git stash apply restores the changes but keeps the entry in the stash list. Use apply when you want to apply the same stash to multiple branches or keep it as a backup.
Yes, use git stash push path/to/file to stash only specific files. You can also use git stash push -p for interactive (patch) mode, which lets you choose which hunks to stash. This is useful when you have mixed changes and only want to set aside part of them.
By default, git stash only stashes changes to tracked files (modified and staged). New untracked files are left in the working directory. Add the -u flag (git stash push -u) to include untracked files, or -a to also include gitignored files.