Skip to article

Git Stash Pop vs Apply: The Difference With Examples

Restore unfinished work with git stash apply or pop, compare the stash list, and learn what happens when changes conflict.

You've saved unfinished work with git stash. Now you want it back. Should you use git stash pop or git stash apply?

Both restore stashed changes. apply keeps the stash entry; pop removes it after a successful application. If pop encounters conflicts, Git keeps the entry. See the Git stash reference for the command behavior.

CommandRestores changesKeeps the stash entry
git stash applyYesYes
git stash popYesOnly if applying fails

Imagine you pause work on a homepage to fix an urgent bug. After the fix, use pop to resume the homepage work and clear its stash entry. Choose apply if you want to inspect the restored changes before removing the saved copy.

Start the first runnable example. The browser terminal already contains a tiny repository on branch main, with one committed file, homepage.txt. Run the three steps in order; resetting the terminal starts over.

To prepare the same example on your own computer, use a new directory and a configured Git commit identity:

mkdir stash-demo
cd stash-demo
git init -b main
printf '%s\n' 'Welcome' > homepage.txt
git add homepage.txt
git commit -m 'Add homepage'

The browser example has already done this setup. Its command blocks begin with the unfinished edit.

01

Save the unfinished homepage draft

Save a change with git stash push

Add a second line to homepage.txt, then inspect git diff. The added line is New homepage draft.

Save the edit with git stash push -m 'Homepage draft'. Afterward, cat homepage.txt prints only Welcome, while git stash list shows:

stash@{0}: On main: Homepage draft

Your working directory is clean, and the unfinished draft is saved separately. The message makes it easier to identify later.

↳ TRY IT / CURRENT IMAGELive Git
cd /home/student/stash-demo
printf '%s\n' 'New homepage draft' >> homepage.txt
git diff
git stash push -m 'Homepage draft'
cat homepage.txt
git stash list

Expected: The diff adds New homepage draft. After stashing, the file contains only Welcome and the stash list contains Homepage draft.

 

02

Apply the stash and keep its saved entry

Example 1: Restore changes with git stash apply

Run git stash apply, then read the file. Both lines are present again:

Welcome
New homepage draft

Inspect the diff and stash list. The draft is a working-tree edit, and stash@{0}: On main: Homepage draft remains listed.

This gives you a separate review step: check the restored work before deciding to remove the saved entry. Applying does not create a regular commit on your branch.

↳ TRY IT / CURRENT IMAGELive Git
cd /home/student/stash-demo
git stash apply
cat homepage.txt
git diff
git stash list

Expected: The draft line is restored, the file is modified, and Homepage draft remains in the stash list.

 

03

Drop the reviewed entry, then compare pop

Example 2: Restore changes with git stash pop

Continue in the same repository. First, drop the stash entry you just reviewed. The restored edit stays in homepage.txt.

Save that edit again with the message Homepage draft again, then run git stash pop.

The draft returns, but this time git stash list prints nothing. git status --short still shows M homepage.txt: popping the stash has not committed your work.

The result in the file matches the apply example. The difference is the empty stash list. You can keep editing or commit the draft when it is ready:

git add homepage.txt
git commit -m 'Update homepage draft'
↳ TRY IT / CURRENT IMAGELive Git
cd /home/student/stash-demo
git stash drop 'stash@{0}'
git stash push -m 'Homepage draft again'
git stash pop
cat homepage.txt
git stash list
git status --short

Expected: The draft line is restored again. The stash list is empty and status shows homepage.txt as modified.

 

What happens if git stash pop causes a conflict?

In your own project, the current branch may contain edits that conflict with the stash. A conflicting pop keeps the stash entry. Edit the affected files, remove conflict markers, and stage the resolution. Review the result before manually dropping the retained entry. This is the conflict workflow described in Git's stash documentation.

For a conflict in homepage.txt, the sequence after editing would be:

git add homepage.txt
git diff --cached
git stash list
# Verify the entry before removing it:
git stash drop 'stash@{0}'

Don't run pop again to finish the first attempt: resolve the changes already in your working tree.

How to apply or pop an older stash

Both commands default to the latest stash. To select another, inspect the list and pass its reference:

git stash list
git stash apply 'stash@{1}'

Alternatively, use git stash pop 'stash@{1}'. Here, stash@{1} identifies the second-most-recent entry. Check the list after adding or dropping entries, because their numbers can change. Git documents this naming in its stash reference.

Should you use apply or pop?

Use apply when you want to review restored work before dropping the entry. Use pop when you're ready to resume and remove the saved entry after success.

For more practice with branches, commits, and everyday recovery, explore the interactive Git course.