Clean up a fork and restart it from the upstream

后端 未结 4 846
南笙
南笙 2020-11-29 14:04

I have forked a repository, then I made some changes and it looks like I\'ve messed up everything.

I wish to start it again from scratch, using the current upstrea

4条回答
  •  粉色の甜心
    2020-11-29 15:01

    Love VonC's answer. Here's an easy version of it for beginners.

    There is a git remote called origin which I am sure you are all aware of. Basically, you can add as many remotes to a git repo as you want. So, what we can do is introduce a new remote which is the original repo not the fork. I like to call it original

    Let's add original repo's to our fork as a remote.

    git remote add original https://git-repo/original/original.git
    

    Now let's fetch the original repo to make sure we have the latest coded

    git fetch original
    

    As, VonC suggested, make sure we are on the master.

    git checkout master
    

    Now to bring our fork up to speed with the latest code on original repo, all we have to do is hard reset our master branch in accordance with the original remote.

    git reset --hard original/master
    

    And you are done :)

提交回复
热议问题