Stashing

26.1 What Stashing Does

Stashing temporarily saves uncommitted changes and restores the working directory to a clean state. This allows you to switch branches or pull updates without committing incomplete work.

26.2 Creating a Stash

To stash all tracked, uncommitted changes:
1git stash

This saves:
• Modified files
• Staged changes
Untracked files are not included by default.

26.3 Stashing With a Message

To make stashes easier to identify:
1git stash push -m "WIP: login form"

26.4 Viewing Stashes

List all saved stashes:
1git stash list

Example output:
1stash@{0}: WIP: login form 2stash@{1}: WIP: navbar fix

26.5 Applying a Stash

Apply the latest stash and keep it:
1git stash apply

Apply a specific stash:
1git stash apply stash@{1}

26.6 Popping a Stash

Apply the latest stash and remove it from the stash list:
1git stash pop

This is the most commonly used stash command.

26.7 Stashing Untracked Files

To include untracked files:
1git stash -u

To include ignored files as well:
1git stash -a

26.8 Dropping and Clearing Stashes

Remove a specific stash:
1git stash drop stash@{0}

Remove all stashes:
1git stash clear

26.9 Common Use Cases

• Switching branches mid-work
• Pulling updates without committing
• Parking experimental changes
• Cleaning working directory quickly

26.10 Key Takeaways

• git stash temporarily saves uncommitted changes.
• Stashes can be listed, applied, popped, or deleted.
• Use messages to manage multiple stashes.
• apply keeps the stash; pop removes it.
• Stashing is reversible and safer than discarding.