Skip to content

Latest commit

Β 

History

History
91 lines (62 loc) Β· 2.22 KB

File metadata and controls

91 lines (62 loc) Β· 2.22 KB

Episode 5: Stash Kung Fu πŸ₯Š

The hidden gem: git stash does way more than you think β€” partial stashes, named stashes, stash branches, and stash-based workflows.

Beyond Basic Stash

Most people know git stash and git stash pop. That's white-belt stash. Here's the black-belt stuff.

Named Stashes

# Stash with a descriptive message
git stash push -m "WIP: half-done search feature"
git stash push -m "experiment: new task format"

# Now your stash list is readable:
git stash list
# stash@{0}: On main: experiment: new task format
# stash@{1}: On main: WIP: half-done search feature

Partial Stash (The Game Changer)

Stash specific files or even specific hunks, not everything:

# Stash only specific files
git stash push -m "just the model changes" -- tasks.py

# Interactive: choose which hunks to stash (like git add -p)
git stash push -p -m "partial work"

-p (patch mode) lets you stash individual chunks of changes. Everything else stays in your working directory.

Stash Untracked and Ignored Files

# Include untracked files (new files not yet added)
git stash push --include-untracked -m "with new files"
# Short form:
git stash push -u -m "with new files"

# Include EVERYTHING, even .gitignore'd files
git stash push --all -m "nuclear stash"

Stash β†’ Branch (Rescue a Stash)

Applied a stash to the wrong branch? Or your stash conflicts with current work?

# Create a new branch from a stash
git stash branch new-feature-branch stash@{0}

This creates a new branch from the commit where the stash was made, applies the stash, and drops it. Zero conflicts guaranteed.

Inspect Without Applying

# See what's in a stash
git stash show stash@{0}

# See the full diff
git stash show -p stash@{0}

# See the stat summary
git stash show --stat stash@{0}

Apply vs Pop

# pop = apply + drop (removes from stash list)
git stash pop

# apply = apply but keep in stash list (safer)
git stash apply stash@{0}

# drop a specific stash manually
git stash drop stash@{1}

Pro tip: Use apply instead of pop until you've verified the apply worked. Then drop manually.

Run the Demo

bash episodes/demos/05-stash-kungfu-demo.sh