Advanced Stash Operations for Context Switching
Master git stash to save, organize, and restore uncommitted work when switching between tasks or branches.
Prerequisites
- -Git installed
- -Uncommitted changes to practice with
Steps
Stash current changes with a descriptive message
Save all tracked modifications and staged changes to the stash with a message for easy identification later.
Always add a message with -m. The default 'WIP on branch' message is not helpful when you have multiple stashes.
Stash including untracked files
The -u flag includes untracked files in the stash. Without it, only modified tracked files are stashed.
Use -a instead of -u to also include ignored files, though this is rarely needed.
List all stashes
View all stashed entries with their index, branch, and message. Stashes are numbered starting at 0 for the most recent.
Inspect a stash without applying it
View the full diff of a specific stash entry. The -p flag shows the patch; without it you only see a file summary.
Apply a specific stash and keep it in the list
Apply the changes from stash@{2} to your working tree. The stash entry remains in the list for future use.
Use 'git stash pop' instead of 'apply' to apply and immediately remove the stash entry.
Drop a stash or clear all stashes
Remove a specific stash entry with drop, or remove all entries with clear.
Dropped stashes cannot be easily recovered. The reflog may help for a short time, but do not rely on it.
Full Script
FAQ
Discussion
Loading comments...