Merge Pull Request from Upstream Branch into a Forked Repository

前提是你 提交于 2019-12-24 10:45:06

问题


I'm new to git, so forgive me for any mistakes I make with my terminology.

I have a forked repo. In the origin repo, someone makes a pull request containing a bunch of different commits. That pull request is then merged into the origin. I would also like that pull request, so I want it merged into my repo too. What's the correct way of doing this? I tried cherry-picking each commit, and that worked, but I feel like that isn't the right way to get things done.

Edit: I'll attempt to more specific about exact structure of what's happening and what I want to do.

There is the original repo we'll call A.

A group of developers forked that repo into a mostly separate project that we'll call B.

I forked B so that I could create my own branches and contribute with pull requests, this is repo C.

There's a change to repo A through a pull request. This PR was made after the fork that created B, and we want the commits from A's PR in repo B.

In order to add it to B, I need to do the same merge they did to A, and do it on my repo C, then make a pull request for B with the changes.

Right now, rather than merge the PR commits from A into C, I instead just cherry picked the commits from the PR and applied them in order. This worked, but I don't feel like this is the best way to do things.


回答1:


  1. Check out the branch you wish to merge to on your fork. Usually, you will merge into master.

    git checkout master

  2. Pull the desired branch from the upstream repository. This method will retain the commit history without modification.

    git pull https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git BRANCH_NAME

  3. If there are conflicts, resolve them. For more information, see "Addressing merge conflicts".

  4. Commit the merge.

  5. Push the merge to your GitHub repository.

    git push origin master



来源:https://stackoverflow.com/questions/48289101/merge-pull-request-from-upstream-branch-into-a-forked-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!