Skip to content

How to Fix Git Stash Pop Conflict

DodaTech 2 min read

In this tutorial, you'll learn about How to Fix Git Stash Pop Conflict. We cover key concepts, practical examples, and best practices.

The Problem

You run git stash pop and get:

Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
The stash entry is kept in case you need it again.

Git could not automatically apply the stashed changes because the working directory has changed since the stash was created. The stash is preserved so you do not lose data.

Quick Fix

Step 1: Resolve the conflicts manually

Open the conflicted files and look for conflict markers:

<<<<<<< Updated upstream
  <h1>Welcome</h1>
=======
  <h1>Hello World</h1>
>>>>>>> Stashed changes

Edit the file to keep the changes you want, then remove the markers.

Step 2: Stage and commit

git add index.html
git commit -m "Resolved stash pop conflicts"

Step 3: Drop the stash

Since the stash is preserved, drop it after resolving:

git stash drop

Step 4: If you want to abort

To discard the conflicts and restore the stash:

git merge --abort  # if in merge state
git checkout -- .  # discard working directory changes
git stash drop     # drop the stash to try again later

Alternative Solutions

Use git stash apply instead of git stash pop. The difference is that apply keeps the stash, giving you time to resolve conflicts without worrying about losing it.

git stash apply
# Resolve conflicts at your own pace
git stash drop   # after everything is resolved

Practice with a Test Repository

cd /tmp
mkdir git-practice && cd git-practice
git init --initial-branch=main
# Initialized empty Git repository in /tmp/git-practice/.git/
echo "test" > file.txt && git add . && git commit -m "init"
# [main (root-commit) abc1234] init

Before running destructive commands on your real repository, practice on a throwaway test repository. This builds confidence and prevents costly mistakes. The reflog is your safety net, but practice makes it less needed.

Additional Troubleshooting

# Check the error message and stack trace for more context
echo "Review the full error output to identify the root cause"

If the above steps do not resolve the issue, examine the complete error message and stack trace. Often the key detail is in the middle of the traceback rather than the final line. Search for the error message in the project documentation or issue tracker for additional solutions.

Prevention

  • Stash only clean work -- commit or discard changes before stashing.
  • Apply stashes soon after creating them to reduce drift.
  • Use git stash branch to apply a stash on a new branch.
  • Check git stash show -p to preview changes before applying.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro