git stash — Temporary Storage
Stash saves your uncommitted changes to a temporary stack, cleans your working directory to match the last commit, and lets you restore everything later. Perfect for context-switching without polluting history with a "WIP" commit.
01.The Stash Stack
The stash works like a stack (LIFO — last in, first out). Each stash push creates a new entry. git stash pop applies and removes the most recent entry. git stash apply applies it but keeps it in the stack (useful for applying the same stash to multiple branches). You can have many stashes — always name them so you know what each one contains.
02.The Classic Context-Switch Scenario
You are halfway through a feature when Slack pings: critical bug in production, fix it now. Your current work is not ready to commit. Solution: git stash (saves WIP, cleans directory), git checkout main, create fix branch, fix the bug, PR and merge, git checkout feature/mine, git stash pop (restores your work exactly). Zero commits wasted.
Commands
What is the difference between git stash pop and git stash apply?