Reset a Branch to Remote State with git

By  on  

Every once in a while I accidentally hose my repository's master branch by merging or committing something I shouldn't.  And then on rare occasion I push that to my remote and then things get all sorts of messed up.  Every PR from that point on has some wonky commits and I look like a noob.  Sometimes the best course of action is to just reset to the a remote branch's master (i.e. the repository I forked the project from) and get on with life that way.  Here's how to do so:

git fetch some-remote   # "origin" if you want to use your own branch
git reset --hard some-remote/master

The first step is fetching a list of branches from the remote.  The next is executing a hard reset of the branch based on the remote.

Now you can stop asking yourself how things got so messed and up can get back to business!

Recent Features

  • By
    JavaScript Promise API

    While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why "hold up the show" when you can trigger numerous requests at once and then handle them when each is ready?  Promises are becoming a big part of the JavaScript world...

  • By
    Camera and Video Control with HTML5

    Client-side APIs on mobile and desktop devices are quickly providing the same APIs.  Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop.  One of those APIs is the getUserMedia API...

Incredible Demos

  • By
    Create a Brilliant Sprited, CSS-Powered Firefox Animation

    Mozilla recently formally announced Firefox OS and its partners at Mobile World Congress and I couldn't be more excited.  Firefox OS is going to change the lives of people in developing countries, hopefully making a name for itself in the US as well.  The...

  • By
    MooTools Text Flipping

    There are lots and lots of useless but fun JavaScript techniques out there. This is another one of them. One popular April Fools joke I quickly got tired of was websites transforming their text upside down. I found a jQuery Plugin by Paul...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!