ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Git Version Control Tutorial• 6 min read

Git Stash: Shelving Work-in-Progress Cleanly

git stash save, git stash pop, git stash list, and stash branches

git stash takes your uncommitted modifications (both staged and unstaged) and shelves them on a temporary stack so you can switch branches to handle urgent hotfixes with a clean working tree.

The Stash Stack Lifecycle

git stash push -m "WIP: checkout redesign": Shelves current work and reverts working tree to the last commit.

git stash list: Views all saved stashes on the stack (stash@{0}, stash@{1}).

git stash pop: Restores the most recent shelved changes and deletes them from the stash stack.

git stash apply: Restores changes but keeps them saved on the stack for safety.

Handling an Urgent Hotfix with Git Stash
# You are mid-way through a feature, but an urgent production bug arises!
# 1. Stash your half-finished work
git stash push -m "wip: halfway through checkout"

# 2. Switch to main and fix production bug
git switch main
git switch -c hotfix/payment-gateway
# ... fix bug and commit ...
git commit -am "fix: patch stripe webhook signature"
git push origin hotfix/payment-gateway

# 3. Return to feature branch and restore stashed work
git switch feature/checkout
git stash pop
git stash enables switching tasks instantly without creating messy work-in-progress commits.
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

What does `git stash pop` do with the most recently shelved stash?