Put unfinished work aside (stash)
When to use this: You have half-done edits but must switch branch or pull, and you are not ready to commit.
Before you start
Steps
-
Stash your changes, including new files
terminalgit 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. -
Do the other thing
terminalgit switch main git pullNow you can switch branches or pull without conflicts from unfinished work.
-
See your stashes
terminalgit stash listNewest first:
stash@{0}is the most recent.Expected output
stash@{0}: On feature-hero: wip: homepage hero -
Bring the work back
terminalgit stash popRe-applies the newest stash and removes it from the list. Use
git stash applyto keep a copy in the list. Switch back to the original branch first if needed.
How to verify it worked
git statusshows your edits again, andgit stash listno 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.