How to add commits to another person's PR on your Github repo

/

January 13, 2020

TLDR

shell
1.git push git@github.com:remoteUser/remoteRepo localBranch:remoteBranch

Explanation

The normal git push command usually looks like this:

1.git push origin branch

Pushing to another developer’s branch follows a similar pattern: origin is the other person’s repo, and branch maps your local branch to the same branch on their remote repo.

origin = git@github.com:remoteUser/remoteRepo

branch = localBranch:remoteBranch

Breaking down each variable:

remoteUser refers to the username of the developer who made the pr on your repo

remoteRepo refers to the name of the repo that the other developer is creating the PR from, usually, this is the same name as your repo.

localBranch refers to the branch name of your local copy of their remote branch

remoteBranch refers to the branch name of that their PR is originating from on their remoteRepo

Keep in mind, that you can only push to PRs from other developers on your repo if that developer selected “Allow edits from maintainers” when they created their PR.

Example

Let’s say you created the open source project, Material Bread. After releasing the project, another developer, with the Github username alburdette619, forks your project and creates a pull request with some new features. While reviewing alburdette619’s PR you realize that his changes will need to be documented in the project’s README.

First, we need to fetch his changes into a branch on our local machine. We can do that using this command:

shell
1.git fetch origin pull/branch/head:branchName

In this case, the branch on his PR is number 306, and I want to name it pr/306:

shell
1.git fetch origin pull/306/head:pr/306

We can now make changes on our local branch pr/306 and commit them:

shell
1.git commit -m "Update Readme with feature xyz"

Finally, we can push these changes to alburdette619’s PR with the new commit using the command defined at the top of the article.

shell
1.git push git@github.com:remoteUser/remoteRepo localBranch:remoteBranch

The remoteUser is alburdette619, the remoteRepo is material-bread, the localBranch is pr/306, and the remoteBranch is 306.

shell
1.git push git@github.com:alburdette619/material-bread pr/306:306