Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 971
Jason Baker Avatar asked Jan 27 '10 13:01

Jason Baker


2 Answers

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

like image 56
Thanasis Pap Avatar answered Sep 21 '22 16:09

Thanasis Pap


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.

like image 32
Jamey Hicks Avatar answered Sep 21 '22 16:09

Jamey Hicks