misaochan
misaochan

Reputation: 890

Git: Reset forked repo to current copy of upstream repo

I made some unwanted changes to my forked copy of an upstream repo, and the upstream repo has also changed in that time. So what I want to do is to basically fork a fresh copy of the upstream repo without keeping any of my changes.

Unfortunately I can't seem to figure out at all how to do this. I have tried three methods:

  1. Following the instructions at How do I update a GitHub forked repository? except for the rebase (I don't want my own commits to be replayed). This tells me I am up to date and no changes are made, but my forked repo is still not the same as the current upstream repo.

  2. Following the instructions at Reset local repository branch to be just like remote repository HEAD . This works with the files and changes them, however it also assumes that I am now editing the upstream repo instead. My forked copy does not reset.

  3. Following the instructions at http://www.hpique.com/2013/09/updating-a-fork-directly-from-github/ however I do not get the option of 'switching the base' when I do that.

I'm quite new to GitHub, unfortunately, which makes everything all the more confusing. I suppose as a last resort I could delete my forked repo and start all over again but I would rather not do that if possible.

Edit: Fixed with VonC's help. Needed to clone the upstream repo to a fresh folder as my local copy instead of the existing folder.

Upvotes: 1

Views: 1768

Answers (1)

VonC
VonC

Reputation: 1327264

If you really want to discard your changes, and reset everything to the upstream (original) repo state, you could:

  • git clone the original repo (not your fork)

  • rename the remote origin to upstream

      git remote rename origin upstream
    
  • add origin with the url of your fork:

      git remote add origin https://github.com/<you>/<yourFork>
    
  • push/reset all the branches to your fork:

      git push origin --force --all
    

(see the discussion for an illustration of those commands)

Upvotes: 3

Related Questions