So this morning I was updating my local development environment and getting the latest code from the upstream repo of a project I have forked on GitHub when I suddenly needed to undo a git pull. For some clarity, my method of forking is done as suggested by GitHub themselves.

The project I’m working on has recently split a new branch for an upcoming 2.0 version, while nightly work is done on master and will likely be released as something like 1.9.5. I have been taking care of some tickets on a branch named release/2.0 but this morning was going to check something out in master.

I logged in as I normally do, typed git pull upstream master and low and behold, was presented with a merge comment suggestion of Merge branch 'master' of into release/2.0. Face…meet palm. If you use git often, you know what I just did…but if you don’t let me explain:

Master and release/2.0 are branches of the code base that, at one some point in the future will be merged. Today is not that day, and I’m not the person to do this. Because I had been working on the release/2.0 branch, when I typed my pull from upstream master, it merged the master branch of the primary project, with my local copy of the release/2.0.

I totally panicked for a second, thinking I’d have to delete and re-clone, but I found a way around this. Two great commands can fix this issue, if you happen to go down the same path I did.

Step 1: Determine the Hash of the previous HEAD

Using the git reflog command, we can get a list of the last 15 references or hashes. Mine looked something like this:

We can see my ‘oops’ is HEAD@{0}, which means, I want the hash of HEAD@{1} or 5f6c496.

Step 2: Reset my local branch

Using the has above, we can now use the git reset command to get local copy of this branch, back to the state the remote is in, and no one will be the wiser.

Hit enter, and then run a git status where you should see a message of something that reads like nothing to commit, working directory clean.

SUCCESS! We’ve now unmerged the pull and merge we did by accident and we can continue coding like nothing ever happened.


By doing this, any work you’ve done between the last successful commit and this pull will be lost. Be sure to stash that away somewhere before you run these commands or you will need to recode it.

Post Promoter Pro

Posted by Chris Klosowski

Hi, I'm Chris Klosowski. Currently I am a Lead Developer of Easy Digital Downloads, where we build the easiest way to sell digital products with WordPress.

I am also the person behind Post Promoter Pro, the most effective way to promote your WordPress Content.


  1. Definitely a good thing to know. Stash is an essential part in this equation!


  2. Leonardo Teixeira December 28, 2016 at 11:52 am

    You saved my life. Thanks.


    1. Glad it helped Leonardo!


  3. You saved a whole day’s worth of work for me, thanks!


  4. I have noticed you don’t monetize your blog,
    don’t waste your traffic, you can earn extra bucks every month.
    You can use the best adsense alternative for any type of website (they approve all websites), for more info simply search in gooogle: boorfe’s tips
    monetize your website


  5. Thanks for the information. It saved my whole day.

    Thank you


  6. Huge saver this blog. Thanks thanks thanks.


  7. easy use git, thanks


  8. It’s being a great help. Thanks man


  9. Life saver post!!! Thanks man!!!


  10. hi chris, you just save my job thanks a lot


  11. Johannes Riecken April 16, 2019 at 4:06 am

    I’m no git expert, but wouldn’t git merge –abort do the same thing?


  12. ddduuuuuuude234 May 3, 2019 at 7:03 am

    Mentioning the caveat *first* would definitely be helpful 🤦🏻‍♂️


  13. You rock! I don’t usually comment but this is EXACTLY what I needed! Thanks!


  14. I have noticed you don’t monetize, don’t waste your
    traffic, you can earn additional cash every month with new monetization method.
    This is the best adsense alternative for any type of website (they approve all sites), for more details simply
    search in gooogle: murgrabia’s tools


  15. God bless u. You saved my day!


  16. […] found lots of info on this online, but this site was the simplest explanation of things for […]


Leave a reply

Your email address will not be published. Required fields are marked *