Go to the pull request Web page and note the PR number at the end of the title, PR_NUMBER
, the contributor GitHub name and branch of the contribution, and at the end of the line right after the title check the destination and contribution in the link. "... into DEST_BRANCH
from CONTRIBUTOR
:CONTRIB_BRANCH
". Last, note the contribution forked repo, visible by clicking on the link, e.g. https://github.com/CONTRIBUTOR/CONTRIB_REPO.git
.
Then use the following commands:
# Get the PR
git clone https://github.com/ORGANIZATION/REPO.git
git checkout -b CONTRIBUTOR-CONTRIB_BRANCH DEST_BRANCH
git pull https://github.com/CONTRIBUTOR/CONTRIB_REPO.git CONTRIB_BRANCH
# Make all your changes, also with multiple commits, e.g.
git add .
git commit -m 'All my changes'
git push https://github.com/CONTRIBUTOR/CONTRIB_REPO.git CONTRIBUTOR-CONTRIB_BRANCH:CONTRIB_BRANCH
This requires that you have write access to the contributor branch (default if you are a reviewer) and will update automatically the PR that you can merge via Web or GitHub CLI. See below if the push fails because you are not authorized to write. The code uses HTTPS URLs, change them if you use SSH.
NOTES
When contributing code it is recommended to use a feature branch in the fork, not main/master, to allow multiple contributions and avoid confusion.
The above code modifies the contributor's branch. As noted in @rmorrin's answer, it is closer to the PR spirit to review and ask the contributor to make the changes. An alternative is to start from the contribution, make the changes, but save them in a new branch. This requires a new PR:
git clone https://github.com/ORGANIZATION/REPO.git
git fetch origin pull/PR_NUMBER/head:pr-PR_NUMBER
git checkout pr-PR_NUMBER
# Make all your changes, also with multiple commits, e.g.
git add .
git commit -m 'All my changes'
# Push your changes
git push origin pr-PR_NUMBER
Then create the new PR from the pr-PR_NUMBER branch (could be on your forked repo if desired), copy the information from the original PR discussion, merge the new PR, and close the original one referencing the new PR. All these solutions preserve the contributor's commit and attribution.
GitHub CLI
If you have the GitHub CLI, many commands can be simplified:
# Get the PR
gh repo clone ORGANIZATION/REPO
gh pr checkout PR_NUMBER
# Make all your changes, also with multiple commits, e.g.
git add .
git commit -m 'All my changes'
# Push your changes
gh pr push
This question and answer are for a reviewer interested in modifying the PR's code. If you are the contributor you can simply update and push your branch, see this question.