Ambuj Jauhari
Ambuj Jauhari

Reputation: 1299

GitHub: reset a fork to the upstream status

I created a fork of a repo. I have done some messy work and want to reset the fork. So I fetched the remote with:

 git fetch XYZ_MASTER

And then I performed:

git reset --hard origin/master

Problem is that now, when I check the status via git status it shows:

On branch master

Your branch and 'origin/master' have diverged,
and have 39 and 3 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

How can I solve this? I'm not sure what to do next. I tried to pull the changes from my fork but it didn't help and resulted in merge conflicts.

Upvotes: 2

Views: 1858

Answers (2)

Momshroom
Momshroom

Reputation: 51

I had some issues with these instructions, but was able to make it work by doing:

git checkout master
git fetch upstream
git reset --hard upstream/master
git push --force

Upvotes: 5

VonC
VonC

Reputation: 1327324

If you have forked a repo, then "origin" references your own repo (the GitHub fork of the original GitHub repo)

If XYZ_MASTER is the remote referencing the original GitHub repo (do a git remote -v to be sure), then a better way to reset your fork would be:

git checkout master
git fetch XYZ_MASTER
git reset --hard XYZ_MASTER/master
git push --force

Upvotes: 0

Related Questions