Skip to main content

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)
Stashes are stored in a stack (LIFO - Last In, First Out):

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:
1

Switch Branches with Changes

Try to switch branches while you have uncommitted changes
2

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
3

Choose Stash

If you select “Stash changes”, Desktop:
  • Creates a stash with branch name
  • Switches to the target branch
  • Saves stash for later restoration

Manual Stashing

Create a stash manually:
1

Have Uncommitted Changes

Make some changes but don’t commit them
2

Open Stash Options

Click Repository > Stash all changes
3

Confirm

Changes are saved to stash and working directory is cleaned

Stash Implementation

From the source code:

Desktop’s Stash Marker

GitHub Desktop tags stashes with !!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

Key Features:
  • Includes untracked files if specified
  • Tagged with branch name
  • Returns false if nothing to stash
  • Uses stash push with message

Listing Stashes

Restoring Stashes

Automatic Restoration

When switching back to a branch:
1

Switch to Branch

Change to a branch that has a stash
2

Stash Notification

GitHub Desktop notifies you if a stash exists for this branch
3

Restore Option

Click Restore stash to apply the changes
4

Stash Applied

Changes are restored to your working directory

Manual Restoration

Restore a specific stash:
1

View Stashes

Click Repository > View stashes
2

Select Stash

Choose the stash you want to restore
3

Pop Stash

Click Restore and delete to pop the stash

Pop vs. Apply

GitHub Desktop uses pop by default:
Pop:
  • Applies stash changes
  • Removes stash from the stack
  • Default in GitHub Desktop
Apply (via command line):
  • Applies stash changes
  • Keeps stash in the stack
  • Allows applying to multiple branches

Stash Conflicts

When restoring a stash causes conflicts:
1

Conflict Detection

GitHub Desktop shows conflicted files
2

Resolve Conflicts

Fix conflicts like any merge:
  • Open in editor
  • Choose “ours” or “theirs”
  • Manually edit conflict markers
3

Stage Resolutions

Resolved files are automatically staged
4

Stash Removed

After successful pop, stash is deleted even with conflicts
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

1

View Stashes

Open the stash list
2

Select Stash

Find the stash you want to delete
3

Delete

Right-click and select Delete stash
4

Confirm

Confirm the deletion

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:
This allows Desktop to:
  • 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:
Shows:
  • Files that were modified
  • Added/deleted line counts
  • File status (added, modified, deleted)

Stash Best Practices

Stash before pulling: If you have uncommitted changes and need to pull, stash first to avoid conflicts.
  1. Don’t Stash Too Long
    • Stashes are temporary storage
    • Apply or commit within a day or two
    • Old stashes can cause conflicts
  2. One Stash Per Branch
    • Avoid multiple stashes on same branch
    • Leads to confusion about which to apply
    • Commit instead if work is substantial
  3. Descriptive Stash Messages
    • When creating via CLI, use: git stash push -m "description"
    • Helps identify stash contents later
    • Desktop auto-tags with branch name
  4. Commit Instead When Appropriate
    • If work is meaningful, commit it
    • Stash is for very temporary saves
    • Commits are safer and more permanent
  5. 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)
Use Commit:
  • 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
Use WIP Commit:
  • Want to push work to remote
  • Need to switch computers
  • Want to track with Git
  • Can amend later

Troubleshooting

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_Desktop marker
  • CLI-created stashes need to be managed via CLI
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}
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
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
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

Command Line Equivalents

For reference, Desktop’s stash operations map to: