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:
This saves:
• Modified files
• Staged changes
Untracked files are not included by default.
1git stashThis 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:
Example output:
1git stash listExample output:
1stash@{0}: WIP: login form
2stash@{1}: WIP: navbar fix26.5 Applying a Stash
Apply the latest stash and keep it:
Apply a specific stash:
1git stash applyApply a specific stash:
1git stash apply stash@{1}26.6 Popping a Stash
Apply the latest stash and remove it from the stash list:
This is the most commonly used stash command.
1git stash popThis is the most commonly used stash command.
26.7 Stashing Untracked Files
To include untracked files:
To include ignored files as well:
1git stash -uTo include ignored files as well:
1git stash -a26.8 Dropping and Clearing Stashes
Remove a specific stash:
Remove all stashes:
1git stash drop stash@{0}Remove all stashes:
1git stash clear26.9 Common Use Cases
• Switching branches mid-work
• Pulling updates without committing
• Parking experimental changes
• Cleaning working directory quickly
• 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.
• 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.