Keeping a fork up to date

前端 未结 3 1981
耶瑟儿~
耶瑟儿~ 2020-12-23 12:25

I wanted to commit somthing to a github repository, but I (obviously) didn\'t have any rights to do so. I made a fork of that repo, commited my changes and submitted a pull-

相关标签:
3条回答
  • 2020-12-23 12:59

    To sync changes you make in a fork with the original repository, you must configure a remote that points to the upstream repository in Git.

    Specify a new remote upstream repository that will be synced with the fork.

    git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
    

    You can check if it was succesful with:

    git remote -v
    

    Then fetch it to update your project:

    git fetch upstream
    

    Merge the changes from upstream/master into your local master branch.

    git merge upstream/master
    

    At last, you can commit new update from original repository to your fork repository.

    This information can also be found on GitHub here and here.

    0 讨论(0)
  • 2020-12-23 13:05

    Adding to Diki Andriansyah answer, rather than using

    git merge upstream/master

    try using:

    git pull upstream master

    This helped me :) .

    0 讨论(0)
  • 2020-12-23 13:12

    I had the same problem and made a docker container that will update the forked branch I care about.

    Try using fork-sync

    The README walks you through how to configure a docker image that will clone, setup a remote to track upstream, fast forward the desired branch, and finally push the changes to your fork. The same container can be started over and over again to keep the branch up to date. I set my docker container to run on a crontab so that every two hours my workstation is updating the forks I regularly contribute to.

    I wanted to be able to make branches which tracked my fork from the tip of upstream. This could have been accomplished with git checkout -b mybranch upstream/master. But this by default sets upstream as the remote, which means if I push my branch will go to the upstream repo, and possible trigger CI jobs. Now, I can do a git checkout -b mybranch origin/master and not have to worry about a dangerous push waiting for me later.

    0 讨论(0)
提交回复
热议问题