Reset fork on GitHub to match origin without deleting fork and recloning
-
I have a fork of both NodeBB and the default composer, and I have some commits that were in rejected PRs that I now want to get rid of, so they don't get folded into future PRs. However, I cannot find a way to 'roll back' my fork to exactly match the original repo.
Is it possible to reset a GitHub fork to match the origin? If so, how?
Paging @accalia as I know she can
git
pretty well.
-
Erm... How the fuck did this end up in Trolleybus?
Paging @Global-Moderators to Jeff this to Coding Help.
Edit: Thanks @Yamikuronue
-
@RaceProUK NodeBB predictive algorithms suggested this would be a git/mercurial flamewar by the time you're done ;)
-
@Yamikuronue said in Reset fork on GitHub to match origin without deleting fork and recloning:
NodeBB predictive algorithms suggested this would be a git/mercurial flamewar by the time you're done
Has the algorithm been modified since Blakey left? Because it seems like it hasn't. ;)
-
@RaceProUK said in Reset fork on GitHub to match origin without deleting fork and recloning:
Is it possible to reset a GitHub fork to match the origin? If so, how?
hmm...
yeah, there's multiple ways to do it.
the way i handle it is
git fetch origin; git fetch upstream; git checkout upstream/master; git branch PR-description-#UpstreamIssueNumber
if i never work in my master branch i never have issues. then u just issue my PR from my branch to their master.
i mean i'm sure there's a way to make it so your master is rolled back and then fast forwarded, but..... it's more hassle than it's worth, and always working in branches lets me have multiple PRs in flight at once if i need to.
-
@RaceProUK In cases like this I always prefer a screenshot of
gitk --all
.It gives an impression of what the different branches are pointing at (though maybe the branch heads may be so far from each other that it won't fit on screen).
-
@RaceProUK said in Reset fork on GitHub to match origin without deleting fork and recloning:
However, I cannot find a way to 'roll back' my fork to exactly match the original repo.
Are you wanting to make it so that branches that are just in the fork go away? (I'm wondering if nuking the fork and making a new one, or even just nuking the unwanted branches, would be enough.)
-
@dkf said in Reset fork on GitHub to match origin without deleting fork and recloning:
Are you wanting to make it so that branches that are just in the fork go away?
I think she probably did stuff in the
master
branch in her fork. Probably going to have to delete the fork and start over.
-
You should be able to rebase your local branch onto the upstream branch (
git rebase <upstream remote>/<branch>
), reset it to the latest upstream commit (git reset --hard HEAD~<number of commits to discard>
) and then force push (git push -f
).
-
@Choonster said in Reset fork on GitHub to match origin without deleting fork and recloning:
You should be able to rebase your local branch onto the upstream branch (
git rebase <upstream remote>/<branch>
), reset it to the latest upstream commit (git reset --hard HEAD~<number of commits to discard>
) and then force push (git push -f
).This seems reasonable assuming it works.
I don't know git that well, even though I've been working with it for roughly six months. If it was me, I would probably tortoisegit -> show log, then pick the revision I want to roll back to, and select "Reset to this revision" and then a force push.
-
@accalia said in Reset fork on GitHub to match origin without deleting fork and recloning:
yeah, there's multiple ways to do it.
Thought there might be.
@accalia said in Reset fork on GitHub to match origin without deleting fork and recloning:
always working in branches lets me have multiple PRs in flight at once if i need to.
I should do that too.
@boomzilla said in Reset fork on GitHub to match origin without deleting fork and recloning:
I think she probably did stuff in the
master
branch in her fork.Yep.
@boomzilla said in Reset fork on GitHub to match origin without deleting fork and recloning:
Probably going to have to delete the fork and start over.
That's what I want to avoid.
@Choonster said in Reset fork on GitHub to match origin without deleting fork and recloning:
You should be able to rebase your local branch onto the upstream branch (
git rebase <upstream remote>/<branch>
), reset it to the latest upstream commit (git reset --hard HEAD~<number of commits to discard>
) and then force push (git push -f
).Hmm… That's given me an idea.
Well, that… worked!
What I did was this:
git fetch upstream git reset --hard upstream/master git push -f
And now my forks are even, my rejected PRs won't pollute future PRs, and I has a happy the size of Texas! Thanks everyone! :D
-
@Choonster said in Reset fork on GitHub to match origin without deleting fork and recloning:
You should be able to rebase your local branch onto the upstream branch
Far too complicated, because then you potentially have conflicts. Do the reset to the last "official" commit first, then fast-forward merge upstream/master, then force push to master.
Edit: Or what @RaceProUK actually did while I wrote that post. ;)