← Back to Mission Control

Temporal Storage

8 min read

Git Stash

Mission Phase 26 • Difficulty: Intermediate

Temporarily Storing Changes

Stash saves your uncommitted changes in temporary storage, letting you switch contexts without committing half-finished work. Think of it as a cargo hold for work in progress.

Basic Stash

git stash

Saves tracked file changes and returns your working directory to the last commit.

Stash with a Message

git stash push -m "Work in progress on sensors"

A descriptive message makes it much easier to find the right stash later.

Include Untracked Files

git stash -u

By default, stash only saves tracked files. The -u flag includes new, untracked files too.

List Your Stashes

git stash list

Output:

stash@{0}: WIP on main: abc123 Latest commit
stash@{1}: On feature: Work in progress on sensors

Apply a Stash

git stash apply            # Apply the most recent stash
git stash apply stash@{1}  # Apply a specific stash

apply keeps the stash in the list after restoring it.

Pop a Stash

git stash pop

pop applies the stash and removes it from the list—the most common workflow.

Drop or Clear Stashes

git stash drop stash@{0}   # Delete one stash
git stash clear            # Delete all stashes

Inspect a Stash

git stash show -p stash@{0}

Shows the full diff of what the stash contains before you apply it.

Common Use Cases

Workflow Example

# Working on a feature when an urgent bug arrives
git stash

# Switch and fix the bug
git switch main
# ...fix, commit, push...

# Return to your feature exactly where you left off
git switch feature-branch
git stash pop

Stashing to a New Branch

git stash branch new-feature stash@{0}

If applying a stash would conflict with your current branch, this creates a fresh branch from the commit where you stashed, then applies the changes there—conflict-free.

Best Practices

Next: Marker Beacons

Your work-in-progress is safe in temporal storage. Next, learn git tag—placing permanent marker beacons on important moments like releases.