Undo a git pull that brought in changes you didn't want
How do I undo a git pull?
Short answer
A pull is a fetch plus a merge or rebase, so undoing it means moving your branch back to where it was. git reset --hard ORIG_HEAD does exactly that, because Git saves your pre-pull position there automatically.
git reset --hard ORIG_HEAD
Returns your branch to exactly where it was before the pull
Does this match your situation?
- A pull brought in commits that broke everything.
- You pulled into the wrong branch.
- A merge commit appeared that you didn't want.
- You pulled when you meant to fetch.
Step-by-step fix
Check what the pull actually did
Look at the last few commits before undoing anything, so you know whether the pull produced a merge commit or simply fast-forwarded your branch.
step 1git log --oneline -5 git reflog -5Reset to ORIG_HEAD
Git writes your previous branch tip into ORIG_HEAD before any pull, merge, rebase or reset. That makes undoing the pull you just ran a single command.
step 2git reset --hard ORIG_HEADORIG_HEAD is overwritten by the next such operation, so use it right away or take the hash from the reflog instead.
Or use the reflog if ORIG_HEAD has moved on
The reflog lists every position your branch has held. Find the entry from just before the pull and reset to that hash.
step 3git reflog # a1b2c3d HEAD@{0}: pull: Fast-forward # f4e5d6c HEAD@{1}: commit: My last commit <- this one git reset --hard f4e5d6cIf you had uncommitted changes, recover them too
A hard reset discards uncommitted work. If the pull auto-stashed your changes they're still on the stash stack, so check before assuming they're gone.
step 4git stash list git stash popPull properly the next time
Fetch first and look at what's incoming; pull only once you're happy. This turns pulling from a leap into a decision.
step 5git fetch origin git log --oneline HEAD..origin/main git diff HEAD...origin/main --stat # happy? then: git pull --rebase
Why this works
Pull isn't a special operation - it's a fetch followed by a merge or rebase, both of which just move your branch pointer and update your files. Undoing it therefore means moving the pointer back, which is exactly what reset does. ORIG_HEAD exists precisely for this: Git records where you were before any operation that significantly moves the branch, so there is always a one-command escape hatch. The fetched commits stay in your object database, harmlessly, until garbage collection.
How to stop it happening again
- Use git fetch and inspect before you integrate, rather than pulling blind.
- Set pull.ff only so a pull that would create a merge stops and asks.
- Commit or stash before pulling so a reset can never cost you uncommitted work.
Commands used in this guide
git resetMove the current branch pointer, optionally rewriting the index and your files.
git reflogThe undo history for everything - the single most important recovery command.
git pullFetch from the remote and immediately integrate the changes into your branch.
git fetchDownload new commits from the remote without changing any of your files.
git stashPark uncommitted work temporarily so you can do something else.
Still stuck?
Search the full command reference and every other rescue guide — there are 56 of them, covering everything from detached HEAD to force-push disasters.
Browse all guides →Frequently asked questions
How do I undo a git pull?
git reset --hard ORIG_HEAD returns your branch to the commit it was on before the pull. If ORIG_HEAD has since been overwritten by another operation, find the pre-pull commit in git reflog and reset to that hash instead.
Does undoing a pull delete the commits I downloaded?
No. They remain in your object database and in origin/main, so they're still there and still fetchable. Only your branch pointer moves back, so your branch no longer includes them.
What is ORIG_HEAD?
A reference Git sets automatically to your previous position before a pull, merge, rebase or reset. It's a built-in one-step undo for the operation you just ran, but it's overwritten each time, so it only helps for the most recent one.
Related rescue guides
How do I undo a Git merge?
If the merge hasn't been pushed, git reset --hard HEAD~1 removes it cleanly. If it has been pushed, use git revert -m 1 <merge-hash> so history stays valid for everyone else. And if you're still in the middle of a conflicted merge, git merge --abort is all you need.
Read the fix →Always fixableGit won't let me pull because of local changes — how do I fix it?
Git is refusing to overwrite uncommitted edits to files the incoming commits also change. Commit them, stash them, or discard them — stashing is the reversible choice and takes one command.
Read the fix →Usually recoverableI ran git reset --hard and lost my commits — how do I undo it?
Committed work is almost never really gone. git reflog lists every position HEAD has held, including the one just before your reset, so you can jump straight back to it with git reset --hard HEAD@{1}. Uncommitted changes that the reset wiped are a different story — those are only recoverable if they had been staged at some point.
Read the fix →Always fixablegit pull says I need to specify how to reconcile divergent branches — what do I choose?
Git 2.27+ refuses to guess whether you want a merge or a rebase when both sides have new commits. Pick one — git config --global pull.rebase true gives you clean linear history and is the best default for most people.
Read the fix →