-2

Say someone submits a PR from a forked repository to my repo on Github. It's 99% OK but for the remaining 1%, I don't want to go back and forth with the PR-review and he-fix and I-review-again cycles, and want to go straightforward and fix them myself.

Is there a way to do further work on github PR myself, i.e., my changes show up in his PR before merging it?

$ git fetch origin pull/11
fatal: couldn't find remote ref pull/11

And the normal git pull command to manually pull the changes of the PR into my local repo doesn't work for me either:

$ git pull
Current branch master is up to date.

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

As when I check the branches in github, there is no branch for that PR:

enter image description here

xpt
  • 20,363
  • 37
  • 127
  • 216
  • You can check out their branch and push your own commits to it – Tyler Liu Jan 08 '23 at 19:34
  • You say there are no branches for that PR, so did the other person push directly to master? – Tyler Liu Jan 08 '23 at 19:46
  • The PR should show what the source and target branches are. Can you confirm that the source branch is master? And can you check the `git log` in your local? Does the other person's commit show up there? – Tyler Liu Jan 08 '23 at 20:40
  • 1
    If you don't see any other branch, it's possible it's a PR coming from a forked repository? See my updated answer for that. – mindaugasw Jan 08 '23 at 20:52
  • 1
    Note that the OP has a very unusual request to actually edit the PR made by someone else, so when someone views the PR it looks like the contributor is proposing changes they did not propose. OP is not interested in actually merging the changes to their master branch. – David Grayson Jan 09 '23 at 01:51
  • Thank you @DavidGrayson for noticing my special request. I want to add my changes on top theirs in the PR, then merge them to the master branch *together*. I don't want to merge an imperfect PR to my master, yet I don't want to go back and forth with the PR-review and he-fix and I-review-again cycles, and want to go straightforward and fix them myself. – xpt Jan 09 '23 at 05:16
  • That's not the same question you originally asked. You said "my changes show up in his PR". So, can you be very specific and clear about what you mean by that so that anyone attempting to answer your question would know if their answer is good enough? You know the PR is just a page on GitHub, right? Why do you want to edit that? Why is it not sufficient for you just to do some work on a branch of your own and then merge it to master, or just do the work directly on master? To me, the most important thing is what ends up on the master branch, not the contents of some old GitHub page. – David Grayson Jan 09 '23 at 05:26
  • The wording (or asking) might change, but the intention never changed -- I don't want to merge an imperfect PR to my master, yet _"I don't want to go back and forth with the PR-review and he-fix and I-review-again cycles, and want to go straightforward and fix them myself"_. The wording or asking get changed because I'm confused of how things should be done. The reason I want to continue with his PR instead of _"do some work on a branch of your own and then merge it to master,"_ is simply I don't want to discredit his contribution by making everything mine @DavidGrayson. I want to merge his PR – xpt Jan 09 '23 at 17:00
  • When you do work on your own branch (after pulling changing in from the contributor's PR), you are making commits on top of his commits and then if you merge it into master his commits will be there in the history permanently, and commands like `git blame` will show him on the lines he changed. I think I'll undelete my answer so you can read it again and try out the procedure. – David Grayson Jan 09 '23 at 17:14

3 Answers3

1

You can do a git pull command to manually pull the changes contributed in the PR into your current branch, whether it is the main branch or a development branch. Just look below the pull request on GitHub and click the little link that says "command line instructions". You can ignore most of the instructions and just look for the one line that starts with git pull.

Then make whatever commits you want to (on top of the pull request, without squashing or amending the commits) and push your changes to wherever is appropriate (e.g. the master branch of your repository on GitHub).

David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • Thanks David, but the contents in "command line instructions" explains how to _perform a manual merge_ on the command line, whereas my question is how to do further work on github PR myself, I.e., my changes show up in his PR before merging it. – xpt Jan 08 '23 at 20:13
  • After performing the git pull command, please follow what I wrote in the last sentence of my answer. (Note that you have to pass arguments to git pull so that it pulls from the right place. You can see the arguments in the GitHub instructions.) – David Grayson Jan 08 '23 at 21:23
  • You last sentence ends with _"push your changes to wherever is appropriate"_, and I was asking how to push my changes to show up in his PR. – xpt Jan 09 '23 at 01:13
  • After further discussion it seems like you are admitting it's not important for your changes to show up in the PR (which is just a page on GitHub); you actually want to merge a correct set of changes into master and make sure that the contributor gets credit for their work. It has been very confusing figuring out what you want. – David Grayson Jan 09 '23 at 17:27
0

You can simply add more commits to the same branch and push them. GitHub Pull Request will be automatically updated with those changes.

Pull Request is a GitHub-only concept. If you're using git, you should checkout the corresponding branch. If you want to checkout a pull request, you should use GitHub CLI instead of git directly (in the documentation linked in your question, notice that command is gh, not git).

If you don't see any other branches in your repository (as per screenshot in the updated question), it's possible that PR was opened from a forked repository by someone else. In that case you can't edit code to be merged directly. Your options:

  • Ask the PR owner to edit the code as you'd like.
  • Merge the PR and edit the code as you wish afterwards.
  • Close the PR and manually merge the code you want. Wouldn't recommend this, since it may be considered rude to the PR owner, taking credit for their work. But if you still want to do it, clone their repository to your computer, checkout the correct branch, merge it into your repository, and push code. See this answer on how to merge code between different repositories.
mindaugasw
  • 1,116
  • 13
  • 18
0

Install gh by saying brew install gh. Then say

gh pr checkout 11

(assuming that that is the correct number of the PR). You can now edit, add, commit, and push. Your commit(s) will be appended to the PR at GitHub.

matt
  • 515,959
  • 87
  • 875
  • 1,141