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
    CSS Gradients

    With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements.  CSS gradients are another step in that direction.  Now that CSS gradients are supported in Internet Explorer 8+, Firefox, Safari, and Chrome...

  • By
    How I Stopped WordPress Comment Spam

    I love almost every part of being a tech blogger:  learning, preaching, bantering, researching.  The one part about blogging that I absolutely loathe:  dealing with SPAM comments.  For the past two years, my blog has registered 8,000+ SPAM comments per day.  PER DAY.  Bloating my database...

Incredible Demos

  • By
    Using Opacity to Show Focus with jQuery

    A few days back I debuted a sweet article that made use of MooTools JavaScript and opacity to show focus on a specified element. Here's how to accomplish that feat using jQuery. The jQuery JavaScript There you have it. Opacity is a very simple but effective...

  • By
    PHP IMDB Scraper

    It's been quite a while since I've written a PHP grabber and the itch finally got to me. This time the victim is the International Movie Database, otherwise known as IMDB. IMDB has info on every movie ever made (or so it seems). Their...


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