Skip to main content

Command Palette

Search for a command to run...

Weekly Git Command #4: git stash -p

Updated
2 min read
Weekly Git Command #4: git stash -p

In last week’s post, I wrote about git stash and how it helps temporarily save your work when you’re not ready to commit.

But very quickly, I ran into a limitation.

Sometimes, I don’t want to stash everything.

I only want to stash some of my changes.

That’s where git stash -p comes in.

What git stash -p does

git stash -p (patch mode) lets you interactively choose which changes to stash, instead of stashing all your modified files at once.

Git shows you your changes in small chunks (called hunks) and asks what you want to do with each one.

Basic usage

git stash -p

After running this, Git will display a portion of your changes and prompt you with something like:

Stash this hunk [y,n,q,a,d,s,e,?]?

The most common options are:

  • y → stash this change

  • n → don’t stash this change

  • q → quit and stash whatever you’ve already selected

You don’t need to memorize everything; y, n, and q are usually enough to get started.

Why this is useful

I’ve found git stash -p especially helpful when:

  • I have unrelated changes in the same file

  • I want to switch branches but keep some work visible

  • I don’t want to commit or stash everything blindly

Instead of undoing changes or making temporary commits, I can be precise about what I set aside.

git stash vs git stash -p

  • git stash Stashes all current changes why

  • git stash -p Stashes selected changes

Once you get comfortable with patch mode, it’s hard to go back.

A small tip

You can also add a message to your stash:

git stash push -p -m "partial refactor"

This makes it much easier to identify later when running:

git stash list

Final thoughts

git stash -p is one of those commands that quietly improves your workflow once you learn it. It gives you control, flexibility, and helps you keep your commits clean.

This post is part of my Weekly Git Command series, where I share Git commands I’m learning while contributing to Git via Outreachy.