38

Is it possible to amend a pull request that someone else has started?

Assume I maintain project X, and User A has sent me a pull request. There's some things I want changed before merging and can quickly do them myself. How can I do this simply and keep it all within one PR?

Is this even possible?

Neil Middleton
  • 22,105
  • 18
  • 80
  • 134

6 Answers6

25

You can do it like this:

In your repo,

git checkout -b new-branch

Then pull User A's commits into your new-branch:

git pull git://github.com/[User A]/[project-name].git

After that, you can change it whatever you like in the new-branch. And when you test and satisfy with your changes, you can merge it into your master branch:

git checkout master
git merge new-branch

OK, now you have your code with User A and your changes.

oppih
  • 860
  • 8
  • 14
  • 1
    What if you don't want to pull the user's master branch but instead some other branch in the tree? http://stackoverflow.com/questions/1709177/git-pull-certain-branch-from-github – netpoetica Jul 16 '14 at 03:34
  • 4
    Branch name is optional second argument to `git pull` – Loren Nov 16 '14 at 23:29
  • 5
    I think ``git fetch upstream pull//head:`` is better than git pull to pull PRs. – sahil shekhawat Jun 17 '15 at 15:42
  • 3
    Will this close the PR at GitHub when I finally push master back to origin? Is it smart enough to understand that what I merged (User A's changes + mine) actually contained the stuff in the pull request? EDIT: I mean, will it mark the PR as merged at GitHub if I do it this way? (when the changes in the pull request is a subset of what was merged). – estan Jan 04 '16 at 17:57
  • 3
    "Will this close the PR at GitHub when I finally push master back to origin?" <- yes, GitHub is smart enough to know it's from the same PR and close it. – dfarrell07 Mar 02 '16 at 19:15
  • Cool! But when I type "git pull" again from new-branch, it says that no tracking information is available. How can I add tracking information for "new-branch" so that it continues to pull from User A? – cxrodgers Jun 28 '16 at 16:58
12

I realize this is an old question, but GitHub has recently introduced some new features that make it possible to actually update a pull request submitted by another user.

When you are creating a new pull request, you'll see a checkbox labelled "Allow edits from maintainers". This is enabled by default.

With this in place, anyone with commit access to the repository that is the target of your pull request will also be able to push changes to the branch of your repository that is the origin of the pull request.

This is especially use in team environments in which everyone has commit access to the "main" repository, but all work is done on feature branches in individual forks. It means that if there is an open pull request that needs some changes and the primary author is unavailable, someone else on the team can make the necessary updates directly, rather than closing the existing PR and opening a new one.

larsks
  • 277,717
  • 41
  • 399
  • 399
3

Assuming you have read and write access to the user's github repository you can push to the branch that the pull request is coming from.

It's on the bottom of the pull request before the MERGE PULL REQUEST button.

You can add more commits to this pull request by pushing to the XXXXX branch on yyyy/zzzzz

sjakubowski
  • 2,913
  • 28
  • 36
1

Unfortunately, no, the following does not work:

git push -f upstream my-updates:refs/pull/999/head ... ! [remote rejected] my-updates -> refs/pull/999/head (deny updating a hidden ref) error: failed to push some refs ...

cdunn2001
  • 17,657
  • 8
  • 55
  • 45
  • Indeed. This behavior is described in the Github documentation: https://help.github.com/articles/checking-out-pull-requests-locally/#modifying-an-inactive-pull-request-locally – waldyrious Aug 06 '16 at 15:54
0

Not possible, but you can submit a second pull request to their branch, which would update the original pull request if they decide to merge it.

nathancahill
  • 10,452
  • 9
  • 51
  • 91
-3

It is possible! All you have to do it check out the branch that is in their pull request and make the changes you want. After you commit and push those changes they should be reflected in the pull request in Github.

jgillman
  • 588
  • 6
  • 14
  • 3
    For future readers: Unless I'm mistaken, you can only do this when the branch is within the main repository. Consider trying to merge `contributor/feature` into `original/master` as the owner of `original/master` – you will not be able to push to `contributor/feature` unless `contributor` – the person submitting the PR – has given you push access to his/her repository. – Sean Allred Nov 19 '14 at 01:43