Modify a pull request in your repository

I recently had to slightly modify the code in a Pull Request that another user submitted to one of my projects on GitHub.
Of course one can comment and suggest a change if one is not satisfied with the request but it was a small change and I had time so I decided to fix it myself.

To my surprise GitHub is surprisingly low on details in how to add a commit to an existing Pull Request of another user and I did not find a 100% satisfactory answer on how to do it the right way, so here is how I did it (I don't know if this is the git-greybeard approved way but it worked for me).

Quick recap: User Alice forked User Bob's repository MyRepo and created a branch fix-branch in which she committed her changes.
Alice has submitted a Pull Request to Bob.
Bob now wants to add a commit to her Pull Request before merging it.

  • create a new remote for Alice's fork:
git remote add Alice git@github.com/Alice/MyRepo.git
  • fetch Alice's history:
git fetch Alice
  • checkout Alice's branch:
git checkout Alice/fix-branch
  • make your changes and commit them:
git add .
git commit -m "YOUR MESSAGE"
  • push the changes to Alice's fork
git push -u Alice HEAD:fix-branch
  • Your commits should now appear in Alice's PR and you can merge it.

This only works if the other user has allowed the owner of the repository to push to their fork. This is the default setting though, so it should work in most cases.


Felix Stein

GitGitHub

255 Words

2020-02-11 01:00 +0100

comments powered by Disqus