Overview
Stashing allows you to temporarily save uncommitted changes without creating a commit. This is useful when you need to switch branches, pull updates, or temporarily set aside work.Save Progress
Temporarily save uncommitted changes
Clean Working Directory
Switch branches without committing
Branch-Specific
Stashes are tagged with the branch they came from
Auto-Cleanup
Desktop automatically manages and cleans up stashes
Understanding Stash
What is a Stash?
A stash is a temporary save of:- Modified tracked files
- Staged changes
- Untracked files (when explicitly included)
When to Use Stash
Good Use Cases:Switch Branches
Temporarily save work to switch to another branch
Pull Changes
Clear working directory before pulling
Experiment
Try something without committing current work
Interrupt Work
Save progress when switching contexts
Stashing in GitHub Desktop
Automatic Stashing
GitHub Desktop automatically stashes changes when:Stash Dialog Appears
GitHub Desktop asks what to do:
- Bring my changes: Move changes to new branch (if possible)
- Stash changes: Save changes and switch
- Cancel: Stay on current branch
Manual Stashing
Create a stash manually:Stash Implementation
From the source code:Desktop’s Stash Marker
!!GitHub_Desktop<branch-name> to:
- Identify which stashes it created
- Associate stashes with specific branches
- Enable automatic cleanup
- Differentiate from manually created stashes
Stashes created outside GitHub Desktop (via command line) are not affected by Desktop’s automatic management.
Creating a Stash
- Includes untracked files if specified
- Tagged with branch name
- Returns
falseif nothing to stash - Uses
stash pushwith message
Listing Stashes
Restoring Stashes
Automatic Restoration
When switching back to a branch:Manual Restoration
Restore a specific stash:Pop vs. Apply
GitHub Desktop uses pop by default:- Applies stash changes
- Removes stash from the stack
- Default in GitHub Desktop
- Applies stash changes
- Keeps stash in the stack
- Allows applying to multiple branches
Stash Conflicts
When restoring a stash causes conflicts:Resolve Conflicts
Fix conflicts like any merge:
- Open in editor
- Choose “ours” or “theirs”
- Manually edit conflict markers
Unlike merge/rebase, there’s no “continue” after stash conflicts. The stash is already applied (or deleted), you just need to resolve and commit.
Dropping Stashes
Delete Specific Stash
Automatic Cleanup
GitHub Desktop automatically cleans up stashes that are no longer needed (implementation details not in current source, but stashes are managed automatically).Moving Stashes Between Branches
GitHub Desktop can reassign a stash to a different branch:- Move stash when you rename a branch
- Reassign stash if branch is deleted
- Keep stash associations accurate
Viewing Stash Contents
See what changes are in a stash:- Files that were modified
- Added/deleted line counts
- File status (added, modified, deleted)
Stash Best Practices
-
Don’t Stash Too Long
- Stashes are temporary storage
- Apply or commit within a day or two
- Old stashes can cause conflicts
-
One Stash Per Branch
- Avoid multiple stashes on same branch
- Leads to confusion about which to apply
- Commit instead if work is substantial
-
Descriptive Stash Messages
- When creating via CLI, use:
git stash push -m "description" - Helps identify stash contents later
- Desktop auto-tags with branch name
- When creating via CLI, use:
-
Commit Instead When Appropriate
- If work is meaningful, commit it
- Stash is for very temporary saves
- Commits are safer and more permanent
-
Test After Popping
- Stashed code might not work in updated codebase
- Always test after restoring a stash
- Resolve conflicts carefully
Common Stash Scenarios
Switch Branches Mid-Work
Pull with Uncommitted Changes
Save Work Before Experimenting
Stash vs. Alternatives
Stash vs. Commit
Use Stash:- Changes are incomplete
- Need to switch contexts quickly
- Work is experimental
- Very short-term save (minutes to hours)
- Changes are a logical unit
- Work should be saved permanently
- Creating checkpoints
- Longer-term save (hours to days)
Stash vs. WIP Commit
Use Stash:- Truly temporary
- Don’t want commit in history
- Very quick context switch
- Want to push work to remote
- Need to switch computers
- Want to track with Git
- Can amend later
Troubleshooting
Stash Not Appearing
Stash Not Appearing
If a stash doesn’t show up:
- It may have been created via CLI without Desktop’s marker
- Check all stashes with:
git stash list - Desktop only shows stashes with
!!GitHub_Desktopmarker - CLI-created stashes need to be managed via CLI
Cannot Apply Stash
Cannot Apply Stash
If stash won’t apply:
- Conflicts: Files have changed significantly since stash
- Deleted files: Files in stash no longer exist
- Uncommitted changes: Clear working directory first
- Try applying manually:
git stash pop stash@{0}
Stash Applied to Wrong Branch
Stash Applied to Wrong Branch
If you accidentally applied a stash to the wrong branch:
- Undo with:
git reset --hard HEAD(loses changes!) - Or commit the changes and cherry-pick to correct branch
- Better: always check current branch before popping
Lost Stash After Conflict
Lost Stash After Conflict
If stash disappeared after conflicts:
- Stash is still applied, just deleted from stack
- Changes are in your working directory
- Resolve conflicts and commit
- Cannot re-stash the exact same entry
Too Many Stashes
Too Many Stashes
If you have many stashes:
- Review with
git stash list - Drop old ones:
git stash drop stash@{n} - Or clear all:
git stash clear(careful!) - Commit or drop - don’t accumulate stashes