How do I update a GitHub forked repository?

前端 未结 23 2783
借酒劲吻你
借酒劲吻你 2020-11-21 11:07

I recently forked a project and applied several fixes. I then created a pull request which was then accepted.

A few days later another change was made by another con

相关标签:
23条回答
  • 2020-11-21 12:05

    When you have cloned your forked repository, go to the directory path where your clone resides and the few lines in your Git Bash Terminal.

    $ cd project-name
    
    $ git remote add upstream https://github.com/user-name/project-name.git
     # Adding the upstream -> the main repo with which you wanna sync
    
    $ git remote -v # you will see the upstream here 
    
    $ git checkout master # see if you are already on master branch
    
    $ git fetch upstream
    

    And there you are good to go. All updated changes in the main repository will be pushed into your fork repository.

    The "fetch" command is indispensable for staying up-to-date in a project: only when performing a "git fetch" will you be informed about the changes your colleagues pushed to the remote server.

    You can still visit here for further queries

    0 讨论(0)
  • 2020-11-21 12:06

    I update my forked repos with this one line:

    git pull https://github.com/forkuser/forkedrepo.git branch
    

    Use this if you dont want to add another remote endpoint to your project, as other solutions posted here.

    0 讨论(0)
  • 2020-11-21 12:06

    I would like to add on to @krlmlr's answer.

    Initially, the forked repository has one branch named : master. If you are working on a new feature or a fix, you would generally create a new branch feature and make the changes.

    If you want the forked repository to be in sync with the parent repository, you could set up a config file(pull.yml) for the Pull app (in the feature branch), like this:

    version: "1"
    rules:
      - base: feature
        upstream: master
        mergeMethod: merge
      - base: master
        upstream: parent_repo:master
        mergeMethod: hardreset
    

    This keeps the master branch of the forked repo up-to-date with the parent repo. It keeps the feature branch of the forked repo updated via the master branch of the forked repo by merging the same. This assumes that the feature branch is the default branch which contains the config file.

    Here two mergemethods are into play, one is hardreset which helps force sync changes in the master branch of the forked repo with the parent repo and the other method is merge. This method is used to merge changes done by you in the feature branch and changes done due to force sync in the master branch. In case of merge conflict, the pull app will allow you to choose the next course of action during the pull request.

    You can read about basic and advanced configs and various mergemethods here.

    I am currently using this configuration in my forked repo here to make sure an enhancement requested here stays updated.

    0 讨论(0)
  • 2020-11-21 12:08

    As of the date of this answer, GitHub has not (or shall I say no longer?) this feature in the web interface. You can, however, ask support@github.com to add your vote for that.

    In the meantime, GitHub user bardiharborow has created a tool to do just this: https://upriver.github.io/

    Source is here: https://github.com/upriver/upriver.github.io

    0 讨论(0)
  • 2020-11-21 12:09

    If you are using GitHub for Windows or Mac then now they have a one-click feature to update forks:

    1. Select the repository in the UI.
    2. Click "Update from user/branch" button the top.
    0 讨论(0)
提交回复
热议问题