Progress:
TIER 1 · MODULE 25· Basics

git stash

Tucks dirty changes onto a stack so you can switch branches.

🎯 What & why

Park your in-progress changes onto a small stack so you can switch contexts cleanly. Stashing creates a stash-commit with parents pointing to your current HEAD and (if -u) the untracked tree.

🧠 Mental model

A stash is a real commit (or two) tucked into refs/stash. The stack is a reflog of refs/stash. git stash list shows entries; git stash pop removes the top and applies it; git stash apply keeps it.

🛠️ Synopsis

git stash list [<log-options>]
git stash show [-u | --include-untracked | --only-untracked] [<diff-options>] [<stash>]
git stash drop [-q | --quiet] [<stash>]
git stash ( pop | apply ) [--index] [-q | --quiet] [<stash>]
git stash branch <branchname> [<stash>]
git stash [push [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet]
          [-u | --include-untracked] [-a | --all] [(-m | --message) <message>]
          [--pathspec-from-file=<file> [--pathspec-file-nul]]
          [--] [<pathspec>...]]
git stash clear
git stash create [<message>]

🎚️ Switches & options

FlagWhat it does
push -m "<msg>"Stash with a message.
-u, --include-untrackedAlso stash untracked files.
-a, --allStash even ignored files.
--keep-index, -kStash unstaged changes only; leave staged content intact.
popApply top stash and drop it.
apply [<stash>]Apply but don't drop. <stash> defaults to stash@{0}.
drop <stash>Discard a specific stash.
clearWipe all stashes. ⚠️ No undo.

📦 Subcommands

push — Save current changes to a new stash entry; default if no subcommand given.
$ git stash push -u -m 'WIP: refactoring auth'
list — Show stashes with their messages.
$ git stash list
stash@{0}: On main: WIP: refactoring auth
show [<stash>] — Show the diff a stash holds; default top of stack.
$ git stash show -p stash@{0}
apply [<stash>] — Re-apply changes without dropping the stash.
$ git stash apply stash@{1}
pop [<stash>] — Apply the top stash and drop it on success.
$ git stash pop
drop [<stash>] — Discard a specific stash without applying.
$ git stash drop stash@{2}
branch <branch> [<stash>] — Create a branch starting at the stash's parent and apply.
$ git stash branch fix-login stash@{0}
clear — Wipe ALL stashes. Irreversible.
$ git stash clear   # ⚠️ no undo

💡 Use cases

🧪 Examples

Quick stash-pop dance.
$ git stash
$ git switch main
$ git pull
$ git switch -
$ git stash pop
Stash with a message and include untracked.
$ git stash push -u -m 'WIP: refactoring auth'
Apply a specific stash without dropping it.
$ git stash apply stash@{2}
Turn a stash into a branch (for proper review).
$ git stash branch stash-fix-login stash@{0}

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.