Skip to main content
Module 5 · Lesson 4 of 521/34 in the course~16 min
Module lessons (4/5)

Context switching cleanly with git stash

Lesson preview5 hands-on exercises readyGit & Modern Collaboration · Module 5 — Undoing Mistakes & Recovery

Shelve unfinished modifications cleanly to ship an urgent hotfix, then restore your state.

What you'll learn in this lesson

  • Shelve unfinished edits safely onto a LIFO stack via git stash push -m "..." without making throwaway commits.
  • Inspect saved stashes with git stash list and distinguish git stash pop (apply + drop) from git stash apply (apply + keep).
  • Switch contexts smoothly for urgent hotfixes and drop finished stashes cleanly with git stash drop.

Overview

Midway through refactoring src/version.ts, your phone rings: production needs a 2-line fix in HOTFIX.md on a clean branch immediately. Your edits aren't ready to commit — yet deleting them hurts!

git stash captures dirty Working Tree & Staging Index modifications onto an internal LIFO stash stack (stash@{0}, stash@{1}, ...) and leaves your workspace spotless right away:

Sections covered in this lesson

  1. 1Shelving Half-Done Work in Seconds
  2. 2Explore Stash Behavior Inside Undo Matrix
Pro Lesson · Module 5 — Undoing Mistakes & Recovery

Unlock "Context switching cleanly with git stash" and the full Git & Modern Collaboration curriculum

Shelve unfinished modifications cleanly to ship an urgent hotfix, then restore your state.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Git & Modern Collaboration plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.