C.W.K.
Stream
Lesson 04 of 05 · published

stash: Temporary Shelf, Not Storage Unit

~18 min · stash, wip

Level 0Untracked Rookie
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

stash is a shelf, not a storage unit

git stash takes your uncommitted work — both staged and unstaged — and puts it on a stack of "saved for later" snapshots, leaving the working tree clean. The use case is the interruption: you are mid-feature when an urgent bug needs a hotfix on main, and you cannot commit yet. Stash, switch, fix, switch back, pop. Five minutes. The interruption did not contaminate your half-done work.

The basic dance is short. git stash push -m "WIP feature/x" saves and clears the working tree. git stash list shows what is saved. git stash pop restores the most recent stash and removes it from the stack; git stash apply restores without removing, useful when you want to apply the same stash to multiple branches. git stash drop <ref> deletes a specific stash; git stash clear wipes all of them.

Two flags matter for daily use. -u (or --include-untracked): include new files Git does not track yet. Without this, untracked files stay in your working tree and might be missed when you switch branches. -k (or --keep-index): stash only the unstaged changes, keep the staged ones in place. Useful for committing the staged piece while shelving the rest.

Stash is a shelf, not storage. The stack survives across branches and stays around indefinitely, but it is local-only and easy to forget about. A stash from three months ago that no one remembers is dead weight, and conflicts can be hard to resolve when the codebase has moved on. The professional habit: stash for short interruptions (hours, not weeks), prefer commits on a WIP branch for anything you might come back to days later. git stash list at the start of a session catches stashes that should be turned into commits or dropped.

Code

Stash dance for an interruption·bash
# Mid-feature, interrupted by urgent bug:
git stash push -m "WIP: feature/profile-page"

# Now working tree is clean. Switch and fix:
git switch hotfix/login-bug
# ... fix, commit, push ...

# Back to feature work:
git switch feature/profile-page
git stash pop

# List what is on the shelf:
git stash list
# stash@{0}: On feature/profile-page: WIP: feature/profile-page
Useful flags·bash
# Include untracked files (very common ask):
git stash push -u -m "WIP with new files"

# Keep the staged piece, only stash unstaged:
git stash push -k -m "shelf the unstaged side"

# Apply without removing from stack (selectively to multiple branches):
git stash apply stash@{0}

# Drop a specific stash:
git stash drop stash@{2}

# Wipe all stashes (DANGER — non-recoverable):
git stash clear

External links

Exercise

Make several modifications across staged and unstaged files plus one untracked file. Stash with -u and a real message. Switch branches, do something else (one commit). Come back, git stash list, then git stash pop. Confirm everything came back including the untracked file. Now create a second stash and intentionally drop it with git stash drop. Note in writing the difference between pop and apply.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.