Git Stash: A Developer’s Temporary Shelf

When working with Git, sometimes you’re in the middle of making changes
but suddenly need to switch branches or work on something else without
committing your unfinished work.\
This is where Git Stash comes in handy.

What is Git Stash?

git s…


This content originally appeared on DEV Community and was authored by Siswoyo Siswoyo

When working with Git, sometimes you're in the middle of making changes
but suddenly need to switch branches or work on something else without
committing your unfinished work.\
This is where Git Stash comes in handy.

What is Git Stash?

git stash temporarily saves (or "stashes") your uncommitted changes in
a hidden area, allowing you to switch branches or pull updates without
losing progress. You can later reapply those stashed changes.

Think of it like a clipboard or shelf: you put your work there, do
something else, and then bring it back when you're ready.

Common Git Stash Commands

1. Save your changes

git stash

This saves staged and unstaged changes, then resets your working
directory to a clean state.

2. Save with a message

git stash save "WIP: login feature"

Adds a label so you know what you stashed.

3. View stash list

git stash list

Example output:

stash@{0}: WIP on feature/login
stash@{1}: WIP on bugfix/header

4. Apply the latest stash

git stash apply

This reapplies the most recent stash, but keeps it in the stash list.

5. Apply a specific stash

git stash apply stash@{1}

6. Pop a stash

git stash pop

Reapplies the most recent stash and removes it from the stash list.

7. Drop a stash

git stash drop stash@{0}

Deletes a specific stash entry.

8. Clear all stashes

git stash clear

Deletes all stashes at once.

Advanced Usage

  • Stash only staged changes:

    git stash --keep-index
    
  • Stash including untracked files:

    git stash -u
    
  • Stash including ignored files:

    git stash -a
    
  • Apply stash to a new branch:

    git stash branch new-feature
    

    Creates a branch from the stash and switches to it.

When to Use Git Stash

✅ When you need to quickly switch branches without committing.
✅ When you want to pull new changes but your working directory is
dirty.
✅ When you are experimenting with changes but not ready to commit them.

❌ Avoid using git stash as a replacement for commits --- it's only
temporary storage.

Summary

  • git stash is like a temporary shelf for unfinished work.
  • Use stash list, stash apply, and stash pop to manage your stashes.
  • Great for context switching without committing half-done work.


This content originally appeared on DEV Community and was authored by Siswoyo Siswoyo


Print Share Comment Cite Upload Translate Updates
APA

Siswoyo Siswoyo | Sciencx (2025-09-08T04:40:21+00:00) Git Stash: A Developer’s Temporary Shelf. Retrieved from https://www.scien.cx/2025/09/08/git-stash-a-developers-temporary-shelf-2/

MLA
" » Git Stash: A Developer’s Temporary Shelf." Siswoyo Siswoyo | Sciencx - Monday September 8, 2025, https://www.scien.cx/2025/09/08/git-stash-a-developers-temporary-shelf-2/
HARVARD
Siswoyo Siswoyo | Sciencx Monday September 8, 2025 » Git Stash: A Developer’s Temporary Shelf., viewed ,<https://www.scien.cx/2025/09/08/git-stash-a-developers-temporary-shelf-2/>
VANCOUVER
Siswoyo Siswoyo | Sciencx - » Git Stash: A Developer’s Temporary Shelf. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/08/git-stash-a-developers-temporary-shelf-2/
CHICAGO
" » Git Stash: A Developer’s Temporary Shelf." Siswoyo Siswoyo | Sciencx - Accessed . https://www.scien.cx/2025/09/08/git-stash-a-developers-temporary-shelf-2/
IEEE
" » Git Stash: A Developer’s Temporary Shelf." Siswoyo Siswoyo | Sciencx [Online]. Available: https://www.scien.cx/2025/09/08/git-stash-a-developers-temporary-shelf-2/. [Accessed: ]
rf:citation
» Git Stash: A Developer’s Temporary Shelf | Siswoyo Siswoyo | Sciencx | https://www.scien.cx/2025/09/08/git-stash-a-developers-temporary-shelf-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.