Git Undo Pull Rebase – Step by Step Guide

git

I just ran

git pull --rebase

and forget to specify "origin". It looks like git pulled from all different branches. Is there a way to revert my repo from here to undo the pull?

Thanks

Best Answer

After a git pull operation, ORIG_HEAD should point to the previous value of HEAD. You should be able to:

git reset --hard ORIG_HEAD

And be back where you started before the pull operation. You can run:

git show ORIG_HEAD

To see exactly where ORIG_HEAD is pointing prior to running the reset command.

An alternative solution would be to create a new branch based on ORIG_HEAD:

git checkout -b newbranch ORIG_HEAD

Verify that things look the way you expect, then delete the old branch and rename new branch.

Also see this question for a discussion of HEAD and ORIG_HEAD and alternate syntaxes for referring to the same thing.

Related Question