A powerful membership solution for WordPress

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 https://github.com/easydigitaldownloads/Easy-Digital-Downloads 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.

Caveats

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.

10 Comments

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

    Reply

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

    You saved my life. Thanks.

    Reply

    1. Glad it helped Leonardo!

      Reply

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

    Reply

  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

    Reply

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

    Thank you

    Reply

  6. Huge saver this blog. Thanks thanks thanks.

    Reply

  7. easy use git, thanks

    Reply

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

    Reply

Leave a reply

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