'Adding to someone else’s pull request on a GitHub project that I do not own

Is it possible for me to add commits to someone else’s pull request on a repository where I am not the owner?

e.g.

User A owns Project X.

User B forks Project X, creates a feature branch, makes some changes, and submits a pull request.

User C likes the pull request, but would like to make some modifications to it. (FWIW User C already has a fork of Project X, so is unable to easily fork User B’s fork).

Can User C add commits to User B’s PR?



Solution 1:[1]

You can check out the branch and re-submit a modified PR (giving credit to the original, preferably).

You can also issue a PR to the PR author:

git remote add userb https://github.com/userb/name.git
git fetch userb
git checkout featurebranch
[change and commit]
git push userc featurebranch

When you create a PR, GitHub lets you choose the base branch - so you can choose the fork and - if you want to - request changes to the PR.

Solution 2:[2]

User C can add directly to User B's pull request if User B has given permission, or possibly if user C is a committer on User A's repo.

https://help.github.com/en/articles/committing-changes-to-a-pull-request-branch-created-from-a-fork

The github default permissions for users on a fork are copied from the original.

If you do have permissions your command line to add would look like this:

git push https://github.com/[userb]/[projectx].git [userc_localbranch]

Solution 3:[3]

With the Github CLI this has become rather easy.

gh repo clone userb/repo
git checkout featurebranch

# make some changes and commit

gh pr create --base featurebranch

# follow instructions

It will automatically create a fork for your user, push the changes to it and open a pull request to the repo of User B. Once User B merges the changes, they will appear in the original PR.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Naylor
Solution 3 Roman