Put unfinished work aside (stash)

careful intermediate #stash#switch branch#pull

When to use this: You have half-done edits but must switch branch or pull, and you are not ready to commit.

Be careful with this one. Stash is local only and easy to forget. List your stashes before you assume something is lost.

Before you start

Steps

  1. Stash your changes, including new files

    terminal
    git stash push -u -m "wip: homepage hero"

    Saves tracked edits and (-u) untracked files, then restores a clean working tree. The message helps you recognise it later.

  2. Do the other thing

    terminal
    git switch main
    git pull

    Now you can switch branches or pull without conflicts from unfinished work.

  3. See your stashes

    terminal
    git stash list

    Newest first: stash@{0} is the most recent.

    Expected output
    stash@{0}: On feature-hero: wip: homepage hero
  4. Bring the work back

    terminal
    git stash pop

    Re-applies the newest stash and removes it from the list. Use git stash apply to keep a copy in the list. Switch back to the original branch first if needed.

How to verify it worked

  • git status shows your edits again, and git stash list no longer lists that stash.

How to undo it

Popped the wrong thing? If it conflicted, Git keeps the stash. Otherwise find it with git fsck --no-reflogs --unreachable --lost-found. The easiest habit is git stash apply first, then git stash drop when sure.

Common errors and fixes

CONFLICT when running git stash pop Resolve the conflict like a merge conflict, then git add the files and run git stash drop (pop keeps the stash when it conflicts).

Q&A

Where is a stash stored?

Inside your local .git folder. It is never pushed to GitHub, so deleting the folder loses it.

Stash or commit to a temporary branch?

For anything you care about, a WIP commit on a branch is safer and visible in git log. Stash is fine for quick, short-lived detours.

Practice these as flashcards →

Terms in this scenario

Related scenarios

My notes

Saved in this browser only.