How do I reset the git master branch to the upstream branch in a forked repository?

后端 未结 4 2080
轮回少年
轮回少年 2020-12-22 16:24

I\'ve completely messed up the master branch of my forked git repo.

I want to completely reset the master branch that was pushed to my fork with the contents of the

4条回答
  •  长情又很酷
    2020-12-22 17:09

    git reset --hard @{upstream}
    

    or, shorter:

    git reset --hard @{u}
    

    Or you can even take it one step further and setup an alias that will allow you to simply type git scrub:

    git config --global alias.scrub 'reset --hard @{upstream}'
    

    (This assumes that your branch is configured to track the corresponding remote branch, which it typically is, unless you are doing something special. See git-branch(1) for more details on tracking and git-rev-parse(1) for details on the branch specification syntax.)

    And then you just git push --force to your fork, as explained in other answers.

提交回复
热议问题