Reputation: 2077
I forked a project someorg/greatproject on github with branches:
* master
* dev
from my fork I made a branch of dev called my-patch. so me/greatproject has branchs:
* master
* dev
* my-patch
I sent in a pull request, the patch was accepted and merged into dev. great! some time later the upstream dev branch got more changes and I wanted to resync my fork with the up stream. I followed some directions (which I have since lost) everything looked okay so I pushed my synced repo back to github.
I came back today and I found out that i had mistakenly merged someorg's dev branch into my my-patch branch. worse yet git branch
shows just
*my-patch
I found out I can checkout origin/dev and if I follow these directions How do I update a GitHub forked repository? I can also checkout upstream/dev, but in both cases that puts me into something called detached head mode, which I guess is bad or wrong or at least merits some weird warnings.
I want to get back to a state where my fork looks like the original, plus the history of my patch's development on the branch my-patch. Basically, the state I would have gotten had all branches (except my patch) in my fork stayed in lock step with the original repo.
How do I get there?
Upvotes: 1
Views: 26
Reputation: 7484
The simplest way to get the main branch (master) up to date and keep your my branch
untouched is:
git remote add originalproject <[email protected]:someorg/greatproject.git>
git checkout master (if master is the main branch for the project)
git reset --hard originalproject/master
You master branch is up to date with the original project
If you want to update your branch to the version that you pushed through the pull request just do
git checkout my-branch (if master is the main branch for the project)
git reset --hard originalproject/my-branch
But you will loose any local changes you have currently. It seems you have done some irreversible changes to your local copy, so the best thing could be to delete the fork and re-fork, while keeping the local folder untouched so you can potentially copy some of the code you did recently to the new clone.
Upvotes: 1