Cerin
Cerin

Reputation: 64709

How to modify someone else's Github pull request?

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?

Upvotes: 39

Views: 24073

Answers (3)

Alex from Jitbit
Alex from Jitbit

Reputation: 60556

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

git push contributor contributor-main:main

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

Upvotes: 17

3D1T0R
3D1T0R

Reputation: 1060

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)

Upvotes: 20

mekoda
mekoda

Reputation: 333

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

Upvotes: 3

Related Questions