简体   繁体   中英

How to accept a pull request (done on master) to a branch?

I got a pull request on a Github from a fork by someone with an interesting idea. The commit was done on the master of the fork. I would like to "accept" that pull request, but only if I am able to check it before, and perhaps enhance it.

So what I would like to do is:

  1. Accept the pull request, but create a new branch in my repository, that then includes the changes.
  2. Work on that branch locally: do some experiments, add unit tests, documentation, ...
  3. When everything is done, decide then to "publish" it by merging the changes to master.

I have searched a lot in the documentation, but it seems not to be possible. The only way it will work is:

  1. The other one has created a branch, worked there, and then did the pull request on that branch.
  2. When I accept it, the branch will be created in my repository.
  3. Then I am able to follow my approach.

If I just accept and merge the pull request, I get

  • Changes directly on the master.
  • Everyone that then clones my repository gets automatically the changes.

So how can I reach the following goals: give credit to the originator, be safe in accepting it, have the option to work further on it?

So I give a detailed view after having read the links from @jonrsharpe (thx.).

You have to do the following steps to get the things accepted on a different branch:

  1. Install locally gh (see gh installation how to do that).
  2. Go to the pull request you got, and select "Open With > Github CLI".
  3. Copy from there the command (in my case gh pr checkout 188 ).
  4. Go to your local checked out project, and start the command there in the terminal.

Now you have locally the branch of the other (if it was a branch), or the commit on the master. In my case, I had the branch already, so now I could do:

  1. Push the branch to Github to make it public.
  2. Go to Github UI, your open pull request and edit it.
  3. Select there now as different branch the branch you just pushed.
  4. Save your changes.
  5. Accept the pull request by merging it.

If the change in the pull request was on the master, you have now the commit on your local master. There are many good descriptions how to do that, for example this: Move the most recent commit(s) to a new branch with Git

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM