Stashing
Stash temporarily saves your uncommitted changes, allowing you to switch contexts without committing incomplete work.
What is Stash?
Stash takes your modified tracked files and staged changes, saves them on a stack, and reverts your working directory to match HEAD.
Before stash:
Working directory has uncommitted changes
After stash:
Working directory is clean (matches HEAD)
Changes saved in stash stackKey points:
- Saves both staged and unstaged changes
- Can include or exclude untracked files
- Works like a stack (last in, first out)
- Changes can be restored later
Quick Reference
Stashes panel in sidebar shows all stashes
When to Use Stash
Quick Context Switch
Need to switch branches but have uncommitted work:
- Stash your changes
- Switch to the other branch
- Do your work there
- Switch back
- Pop your stash
Pulling with Local Changes
Your local changes conflict with incoming changes:
- Stash your changes
- Pull the latest
- Pop your stash
- Resolve any conflicts
Experimenting
Want to try something different without losing current work:
- Stash current changes
- Experiment freely
- If experiment fails, pop your stash
- If experiment succeeds, drop the stash
Moving Changes to Another Branch
Started work on the wrong branch:
- Stash your changes
- Checkout the correct branch
- Pop your stash
Stash Use Cases
| Scenario | Action |
|---|---|
| Need to switch branches quickly | Stash, switch, work, switch back, pop |
| Pull would conflict | Stash, pull, pop, resolve conflicts |
| Wrong branch | Stash, checkout correct branch, pop |
| Want to test something | Stash, experiment, pop or drop |
| Clean working directory needed | Stash, do clean operation, pop |
Creating a Stash
Basic Stash
- Click Stash in the toolbar (or use keyboard shortcut)
- Enter an optional message to identify the stash
- Click Create Stash
TIP
Always add a descriptive message. "WIP" doesn't help when you have multiple stashes.
Stash Options
| Option | Description |
|---|---|
| Include untracked files | Also stash new files not yet tracked by Git |
| Keep staged changes | Only stash unstaged changes, leave staged alone |
| Include ignored files | Also stash files matching .gitignore |
Select options in the Stash dialog before creating
Stash Specific Files
- Stage only the files you want to stash
- Create stash with Keep staged changes disabled
- Or right-click specific files and select Stash
Viewing Stashes
Click Stashes in the sidebar to see all stashes Click a stash to preview its contents before applying
Each stash shows:
- Message - Your description (or auto-generated)
- Branch - Where the stash was created
- Date - When it was stashed
- Changes - Files modified
Applying Stashes
Apply
Restores the stashed changes but keeps the stash for future use.
- Select the stash in the Stashes panel
- Click Apply
- Changes are restored to working directory
Use when you might need the same changes again.
Pop
Restores the stashed changes and deletes the stash.
- Select the stash
- Click Pop
- Changes restored, stash removed
Use when you're done with the stash.
Apply to Different Branch
Stashes aren't tied to branches:
- Checkout any branch
- Apply or Pop the stash
- Changes appear in current branch
Conflicts
If stashed changes conflict with current state, you'll need to resolve conflicts manually.
Managing Stashes
Renaming
Right-click a stash and select Rename to update its message
Creating Branch from Stash
If stashed changes are significant:
- Right-click the stash
- Select Create Branch
- Enter branch name
- Stash is applied to new branch
Dropping a Stash
To delete a stash without applying:
- Right-click the stash
- Select Drop
- Confirm deletion
Cannot Undo
Dropped stashes cannot be easily recovered. The changes are lost unless you can find them in reflog.
Clear All Stashes
- Click the menu in stash panel
- Select Clear All
- Confirm deletion
Stash Conflicts
When applying a stash conflicts with current changes:
- Conflicting files are marked
- Open conflict resolver
- Choose which changes to keep
- Mark as resolved
- Stash remains (wasn't popped due to conflict)
After resolving, manually drop the stash if no longer needed.
Best Practices
Use Descriptive Messages
Bad: "WIP"
Good: "WIP: user authentication - login form validation"Don't Hoard Stashes
Review and clean up stashes regularly. Old stashes become confusing and may no longer apply cleanly.
Consider Commits Instead
For longer interruptions, consider committing with a "WIP" message instead:
- Commits are more permanent
- Easier to track in history
- Can be amended or squashed later
Stash Before Risky Operations
Before rebasing, resetting, or other potentially destructive operations:
- Stash any uncommitted changes
- Perform the operation
- Pop your stash
Comparison: Stash vs Commit
| Aspect | Stash | Commit |
|---|---|---|
| Permanence | Temporary | Permanent |
| History | Not in branch history | Part of history |
| Visibility | Local only | Can be pushed |
| Use case | Quick context switch | Checkpoint or milestone |
| Recovery | Can be lost | Always recoverable |
