DEV Community

Shariful Ehasan
Shariful Ehasan

Posted on

Git Stash Made Simple: Save Your Work Without Committing

Ever been midway through a feature and suddenly need to fix a bug or pull updates? That’s where Git stash comes in. It lets you temporarily save uncommitted changes without creating a commit, giving you a clean working directory to switch tasks—without losing progress.

How It Works

Git stash saves your current changes (staged or unstaged) on a stack, resets your working directory to the last commit, and lets you reapply those changes later. Stashes live locally—they aren’t pushed to GitHub.

Quick Commands

  • git stash → stash tracked files

  • git stash -u → include untracked files

  • git stash push -m "message" → stash with a note

  • git stash list → see all stashes

  • git stash apply → reapply latest stash

  • git stash pop → reapply and remove stash

You can also create a new branch from a stash using git stash branch <name> —super handy for experimenting.

Example Workflow

  1. Save your half-done feature:
git stash push -m "Half-done login feature"
Enter fullscreen mode Exit fullscreen mode
  1. Switch to main, fix a bug, commit your changes.

  2. Return to your feature branch:

git stash pop
Enter fullscreen mode Exit fullscreen mode

Conflicts? Resolve them like any merge conflict.

Tips for Beginners

  • Always add a message with -m to remember what’s in each stash.

  • Use -u to include new files you haven’t tracked yet.

  • Clean up old stashes with git stash drop or git stash clear.

  • For longer work, consider creating a temporary branch instead.

Git stash keeps your workflow flexible and clean, letting you handle interruptions without messy “WIP” commits. Master it, and you’ll switch tasks like a pro.

Top comments (0)