Reputation: 64709
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
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
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:
Make comments on the code in their Pull Request:
Accept it as is, then fix it in your own repository
Upvotes: 20
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