Skip to content

Instantly share code, notes, and snippets.

@wtbarnes
Created March 5, 2020 04:49
Show Gist options
  • Star 62 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save wtbarnes/56b942641d314522094d312bbaf33a81 to your computer and use it in GitHub Desktop.
Save wtbarnes/56b942641d314522094d312bbaf33a81 to your computer and use it in GitHub Desktop.
Brief instructions for how to modify and push to someone else's PR on github

How to Push to Someone Else's Pull Request

Let's say contributor has submitted a pull request to your (author) project (repo). They have made changes on their branch feature and have proposed to merge this into origin/master, where

origin -> https://github.com/author/repo.git

Now say you would like to make commits to their PR and push those changes. First, add their fork as a remote called contributor,

> git remote add contributor https://github.com/contributor/repo.git 

such that,

> git remote -v
origin      https://github.com/author/repo.git (fetch)
origin      https://github.com/author/repo.git (push)
contributor   https://github.com/contributor/repo.git  (fetch) 
contributor   https://github.com/contributor/repo.git  (push)

Next, pull down their list of branches,

> git fetch contributor

and create a new branch (contributor-feature) from the branch that they have created the PR from,

> git checkout -b contributor-feature contributor/feature

Now make any changes you need to make on this branch. If you'd like to rebase this PR on top of the master branch of the primary repository,

> git rebase origin/master

Finally, push the changes back up to the PR by pushing to their branch,

git push contributor contributor-feature:feature

Note that if you did a rebase, you'll need to add the --force (or -f) flag after push. The author of the PR also may need to explicitly allow you to push to their branch.

Helpful Links

@Blaumaus
Copy link

Thank you for this tutorial.

@edimetia3d
Copy link

The author of the PR also may need to explicitly allow you to push to their branch.

Another note:

  1. It seems only maintainer of author/repo.git could push commit to contributor's branch.
  2. As a contributor, you need to un-check the Allow edits by maintainers box in PR page to disable maintainer's pushing permission, and it is checked by default.

It bothered me for a while, because someone pushed code into my fork, I just feel somehow strange.

@Anas-mhameed
Copy link

Thank you so much my friend

@projectkepler-ru
Copy link

based

@stephenwaite
Copy link

bradys-panda

@silverqx
Copy link

I thought that's how it works, but it still helped me a lot to get my bearings (orientate). Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment