git_stash
git stash
Temporarily save uncommitted changes.
๐พ Basic Stashing
Stash Current Changes
git stash
Saves all uncommitted changes and reverts to clean working directory.
Stash with Message
git stash push -m "Work in progress on login"
Stashes changes with a descriptive message.
Stash Including Untracked
git stash -u
Stashes changes including untracked (new) files.
Stash Everything
git stash -a
Stashes all files including untracked and ignored files.
Stash Specific Files
git stash push path/to/file.txt path/to/other.txt
Stashes only the specified files.
Stash with Keeping Staged
git stash --keep-index
Stashes only unstaged changes. Staged changes remain staged.
๐ View Stash List
List All Stashes
git stash list
Shows all stashed changes. Example output:
stash@{0}: WIP on main: abc1234 Commit message
Show Stash Contents
git stash show
Shows summary of most recent stash.
Show Stash Diff
git stash show -p
Shows full diff of most recent stash.
Show Specific Stash
git stash show stash@{2}
Shows summary of specific stash.
๐ Stash Flow
graph LR
A[Working Changes] -->|git stash| B[Stash Stack]
B -->|git stash pop| A
B -->|git stash apply| C[Working Changes + Stash Kept]
โฉ๏ธ Restore Stash
Apply and Remove Stash
git stash pop
Applies most recent stash and removes it from stash list.
Apply and Keep Stash
git stash apply
Applies most recent stash but keeps it in stash list.
Apply Specific Stash
git stash apply stash@{2}
Applies a specific stash from the list.
Pop Specific Stash
git stash pop stash@{2}
Pops a specific stash.
๐๏ธ Delete Stash
Drop Most Recent Stash
git stash drop
Removes most recent stash without applying.
Drop Specific Stash
git stash drop stash@{2}
Removes a specific stash.
Clear All Stashes
git stash clear
โ ๏ธ Removes all stashes. Cannot be undone!
๐ฟ Stash and Branch
Create Branch from Stash
git stash branch new-branch-name
Creates new branch from where stash was made and applies stash.
Create Branch from Specific Stash
git stash branch new-branch stash@{2}
Creates branch and applies specific stash.
๐ก Tips
git stash
git pull
git stash pop
If you have uncommitted changes, stash before switching.
If pop causes conflicts, the stash is NOT dropped. Use git stash drop after resolving.
๐ Related
#git #stash #temporary #advanced