How do revert a local branch back to how it is in github?

34,687

Solution 1

Just to make sure I understand the state of things: you created the release branch but did not check it out, so your commits are on the development branch in your local repository. You said you merged the changes into the release-v0.2.0b branch.

If that is the case, and there are no other commits on the development branch you need to preserve, just delete the local copy of the development branch and check it out again from origin.

First, verify what branches you have and which one you are on:

git branch -av

Then switch away from the development branch so you can delete it:

git checkout origin/development
git branch -D development

That actually leaves you on no branch, but you'll get back on a branch when you check it out again from the origin:

git checkout origin/development -b development

I suggest checking out origin/development to avoid unnecessary churning of files in your snapshot.

Solution 2

Even quicker you can just reset a local branch to a specific remote:

git reset --hard remote/branch

Where "remote" the name of your remote
Where "branch" the name of the remote branch

Solution 3

Go back to the local release branch you want the changes in, Pull there from github.

git checkout local-branch-that-refers-public-v0.2.0b
git pull origin release-v0.2.0b

Then, reset the branch pointer of the local branch that you committed to the earlier commit you want to go back to.

git checkout release-v0.2.0b
git reset HEAD^
Share:
34,687
Jason Baker
Author by

Jason Baker

I'm a developer on Google's Cloud Console.

Updated on July 09, 2022

Comments

  • Jason Baker
    Jason Baker almost 2 years

    I did a bit of development against the wrong branch in my local repository. I did a git branch without next doing a git checkout. The commands look something like this:

    #On branch development
    git branch release-v0.2.0b
    # changes and several commits
    git push origin release-v0.2.0b
    

    And that's when I realized I was working on the wrong branch. My github repo is in the proper state, but my local repo isn't. I've merged the changes from development into release-v0.2.0b, but I'd like to reset development back to the way it is in my github repo. What's the best way to go about this?

  • Jonathan Arkell
    Jonathan Arkell almost 11 years
    Thanks. This answer is exactly what I was looking for, and should be the correct one.