Lesson

Git Stash

10 min reading
Free Course

Git Stash: Shelving Uncommitted Changes Safely

git stash saves your uncommitted tracked edits on a temporary stack and resets your working directory back to the last commit. Use it when you need to switch branches urgently for a hotfix without creating a messy half-finished commit.

Saving Stashes with Descriptive Messages

Always include -m when stashing so you remember what each entry contains days later. Include -u (or --include-untracked) if you also created new files like assets/banner.svg:

git stash push -u -m "WIP header navigation styling"

After stashing, git status reports a clean working tree, letting you switch branches or run git pull cleanly.

Listing, Inspecting, and Restoring Stashes

View every saved entry on the stash stack and preview the files changed in a specific entry:

git stash list
git stash show -p stash@{0}

When you are ready to resume work, restore the changes using either apply or pop:

  • git stash apply restores the changes onto your current branch and keeps the stash in your list as a backup.
  • git stash pop restores the changes and deletes the stash entry if no merge conflicts occur.
git stash pop

Creating a Branch from a Stash and Cleaning Up

If the target branch changed heavily while your work was stashed, applying it directly might cause conflicts. Create a fresh branch directly from the original commit where you stashed:

git stash branch feature/header-nav stash@{0}

To remove a specific old stash or wipe the entire stash stack:

git stash drop stash@{1}
git stash clear

Common Stashing Mistakes

Relying on git stash as long-term storage leads to forgotten code buried under stash@{5}. If work takes more than a day, commit it to a feature branch instead. Also remember that git stash skips untracked files unless you pass -u.

Frequently Asked Questions

What happens if git stash pop hits a merge conflict?

Git leaves the conflicting markers in your files and does not drop the stash entry. Resolve the conflict, stage your files, and run git stash drop manually when finished.

Can I stash only one file while keeping other edits in my workspace?

Yes. Run git stash push -m "Save styles only" -- styles.css to stash specific paths while leaving other modified files untouched.

Are stashes included when I push to GitHub?

No. The stash stack lives strictly in your local .git folder and is never uploaded by git push.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol
Git Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum