my-notes

git_stash

1 min read

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

Quick Stash and Pull
git stash
git pull
git stash pop
Stash Before Switching Branches

If you have uncommitted changes, stash before switching.

Stash Conflicts

If pop causes conflicts, the stash is NOT dropped. Use git stash drop after resolving.



#git #stash #temporary #advanced

Built with mdgarden