How do I update a GitHub forked repository?

前端 未结 23 2854
借酒劲吻你
借酒劲吻你 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条回答
  •  猫巷女王i
    2020-11-21 12:00

    Starting in May 2014, it is possible to update a fork directly from GitHub. This still works as of September 2017, BUT it will lead to a dirty commit history.

    1. Open your fork on GitHub.
    2. Click on Pull Requests.
    3. Click on New Pull Request. By default, GitHub will compare the original with your fork, and there shouldn't be anything to compare if you didn't make any changes.
    4. Click switching the base if you see that link. Otherwise, manually set the base fork drop down to your fork, and the head fork to the upstream. Now GitHub will compare your fork with the original, and you should see all the latest changes.
    5. Create pull request and assign a predictable name to your pull request (e.g., Update from original).
    6. Scroll down to Merge pull request, but don't click anything yet.

    Now you have three options, but each will lead to a less-than-clean commit history.

    1. The default will create an ugly merge commit.
    2. If you click the dropdown and choose "Squash and merge", all intervening commits will be squashed into one. This is most often something you don't want.
    3. If you click Rebase and merge, all commits will be made "with" you, the original PRs will link to your PR, and GitHub will display This branch is X commits ahead, Y commits behind .

    So yes, you can keep your repo updated with its upstream using the GitHub web UI, but doing so will sully your commit history. Stick to the command line instead - it's easy.

提交回复
热议问题