My workflow with pull requests from forks

As a long time open source maintainer, I occasionally have to modify pull requests made by contributors via forks. If a contributor needs help adding/fixing tests, or addressing linter errors, it is often simpler for me to modify a pull request by adding a commit to their branch. I like this workflow as I can help the contributor out, and give them the option to revise my changes as well. I push changes to contributor forks infrequently enough, that I usually have to look how to do it each time, which led this post being written.

The high-level workflow I want is:

  1. Get the contents of the pull request onto my machine.
  2. Make some changes.
  3. Push our modified branch back to the fork and update the pull request.

Thankfully, GitHub generates a branch-ref that fits this scenario perfectly. First, I check out the pull request branch locally:

Show Plain Text
  1. git fetch origin pull/17563/head:pull-17563
  2. git switch pull-17563

This will fetch a branch from the origin repository (pull/17563/head), and create a local branch (pull-17563). With our changes complete, I make a commit and then push the branch back to the contributors fork:

Show Plain Text
  1. git add remove $user git@github.com:$user/$repo
  2. git push $user pull-17563/$user-branch

Pushing branches to contributor forks does require that the contributor allowed ‘maintainers can make changes’ option, but it is on by default.

Comments

There are no comments, be the first!

Have your say: