Tucks dirty changes onto a stack so you can switch branches.
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.
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.
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>]| Flag | What it does |
|---|---|
push -m "<msg>" | Stash with a message. |
-u, --include-untracked | Also stash untracked files. |
-a, --all | Stash even ignored files. |
--keep-index, -k | Stash unstaged changes only; leave staged content intact. |
pop | Apply top stash and drop it. |
apply [<stash>] | Apply but don't drop. <stash> defaults to stash@{0}. |
drop <stash> | Discard a specific stash. |
clear | Wipe all stashes. ⚠️ No undo. |
$ git stash push -u -m 'WIP: refactoring auth'$ git stash list
stash@{0}: On main: WIP: refactoring auth$ git stash show -p stash@{0}$ git stash apply stash@{1}$ git stash pop$ git stash drop stash@{2}$ git stash branch fix-login stash@{0}$ git stash clear # ⚠️ no undo$ git stash
$ git switch main
$ git pull
$ git switch -
$ git stash pop$ git stash push -u -m 'WIP: refactoring auth'$ git stash apply stash@{2}$ git stash branch stash-fix-login stash@{0}push -m 'WIP <topic>' so git stash list is readable.git stash branch is cleaner than apply.git stash without -u ignores untracked files. Lots of 'where did my new file go?' moments.stash pop after a conflict: stash stays on the stack until you drop it manually.stash clear is destructive. No reflog for individual entries after clearing.Hit each option, then Check answers. Score is recorded; Next is always open.