31

Someone created a pull request on my Github repo. It mostly looks good, but I had to make a few minor changes to get it to pass my continuous integration server.

Github's on-screen instructions to "review" the request were to run:

git checkout -b otheruser-fix_somebug
git pull https://github.com/otheruser/myrepo.git fix_somebug

I then made my changes, and committed locally. However, when I went to run git push, git informed me:

fatal: The current branch otheruser-fix_somebug has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin otheruser-fix_somebug

which I did, but my changes are not showing under the pull request, but instead under a copy of the branch otheruser-fix_somebug mirrored on my Github repo and unconnected to the pull request.

How should I have called git push to get the changes to appear on the pull request?

Cerin
  • 60,957
  • 96
  • 316
  • 522
  • 1
    IIUC a pull request can only contain changes from the branch from which the request was submitted. – jingx May 17 '17 at 21:00
  • 1
    Did they fork the repo and open a PR across the forks? – osowskit May 18 '17 at 05:11
  • Current github documentation on its pull-request modify workflow: [Committing changes to a pull request branch created from a fork](https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/committing-changes-to-a-pull-request-branch-created-from-a-fork) – maxschlepzig Jan 03 '21 at 17:33

3 Answers3

20

To my knowledge, you can only do this if they grant you permission. In the past this was only possible by them adding you as a contributor on their fork, however, in September 2016, GitHub added a feature for exactly this use case, allowing the person requesting the Pull Request to give permission to the maintainer(s) of the upstream repository simply by marking a checkbox.

You can make a comment on the Pull Request, telling them that their are some issues you'd like to fix before merging the Pull Request, and stating that you'd like them to give you permission to commit to their Pull Request branch by checking the "Allow edits from maintainers" checkbox on the Pull Request, and giving them a link to the GitHub Help page about the feature, so they can see exactly how to enable it. Once they've done so, you can push to the Pull Request branch of their repository directly.


Things you can do if they haven't/won't give you write access to their pull request branch:

  • Make comments on their Pull Request:

    1. Go to the Pull Request in your browser
    2. Scroll to the bottom of the "Conversation" (default) page
    3. Post comments describing the changes they need to make before you'll accept the PR.
  • Make comments on the code in their Pull Request:

    1. Go to the Pull Request in your browser
    2. Clicking the "Files changed" link at the top
    3. Hover over a line of code that should be changed
    4. Clicking the little blue "+" button that appears next to it
      (NB: these only appear on changed, and nearby lines)
    5. Post a comment and/or some code to fix what's there
    6. Repeat 3-5 as needed.
  • Accept it as is, then fix it in your own repository

    1. Merge their branch as if there was nothing wrong with it
    2. Make a new commit to your repository that fixes the issues (preferably mentioning the PR by issue id in your commit message so that GitHub can tell it's related and show it in the PR's Conversation page)
3D1T0R
  • 1,050
  • 7
  • 17
  • Since writing this answer I've become aware of [this GitHub blog post](https://github.com/blog/2247-improving-collaboration-with-forks) which is about doing exactly this using [this feature](https://help.github.com/articles/committing-changes-to-a-pull-request-branch-created-from-a-fork/), but only if [they grant you access](https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/). – 3D1T0R Jul 29 '17 at 18:06
  • @Cerin: I've edited the answer to include information on GitHub's "Allow edits from maintainers" Pull Request feature. – 3D1T0R Jul 30 '17 at 00:10
  • As a maintainer, is there a simple way for me to find out whether a given pull-request grants me edit permissions? – maxschlepzig Jan 03 '21 at 17:34
  • None of this practical. People in open-source disappear all the time which is the whole point of needing to commander their PR. Code can't land as-is because CI blocks and main should not be broken. The only thing I've found to do, is copy their branch and close PR- just not a great workflow. – Trevor Hickey Jan 27 '22 at 06:35
3

Step 1: in your local repo add a new remote pointing to contributor's

git remote add contributor https://github.com/contributor/repo.git 

You will now have two remotes - origin and conritbutor. To verify - run this: git remote -v

Step 2: fetch from new remote

git fetch contributor

Step 3: create a new branch from their changes

git checkout -b contributor-main contributor/main

(replace "main" with "master" if needed)

Step 4: Make changes, commit and push

If the contributor has "allowed changes form maintainers" when creating the PR (most do b/c it's the default option), the new commit will show up in the PR instantly

P.S. Replace "contributor" with the user's name

Alex from Jitbit
  • 53,710
  • 19
  • 160
  • 149
  • Push new branch? To which remote? UPD: nevermind, it's automatically tracking pull request branch under local name. `git push contributor HEAD`. Though I've got "permission denied" anyway. Probably contributor disabled it ( – Nakilon May 14 '23 at 06:05
2

What about checking out the branch from the Pull Request? Then you can do the commit there, and push to that branch directly.

git fetch
git checkout fix_somebug

add the commit with your changes

git push origin fix_somebug
mekoda
  • 313
  • 2
  • 13
  • 1
    It sounds like that's exactly what they did, and they explained what the issue w/that approach was in the question. – Adrian Jun 01 '17 at 21:02
  • 1
    @Adrian I think it's different: in his approach, he branched out from the PR branch and added the new commit in that new branch. I propose to checkout exactly the PR branch (note the difference when checking out) and make changes there, and then push those changes to the already existing PR branch. – mekoda Jun 02 '17 at 03:31
  • From the question, it looks like he did check out the PR branch itself, but it's not stated explicitly either way, so it's hard to tell. – Adrian Jun 02 '17 at 13:03
  • 1
    Yes, it is stated in the question. He checked out the PR branch, then tried to push back to the PR branch, only to find that it instead created a new branch on his repo for his changes because he didn't have write privileges on the PR branch. – 3D1T0R Jul 30 '17 at 00:13