16

I have forked a repo in github. There are some new pull requests in the Upstream. I want to pull a pull request from upstream locally.

How can I do that? I have no idea and found nothing related to this.

mahinlma
  • 1,208
  • 3
  • 11
  • 24
Noor A Shuvo
  • 2,639
  • 3
  • 23
  • 48
  • Possible duplicate of [How to pull a pull request quickly locally](https://stackoverflow.com/questions/6389127/how-to-pull-a-pull-request-quickly-locally) – phd Jan 04 '19 at 10:08
  • https://stackoverflow.com/search?q=%5Bgithub%5D+pull+request+locally – phd Jan 04 '19 at 10:08

5 Answers5

19

You should be able to do this by first adding the upstream as remote, and then pulling the pull request:

git remote add upstream https://github.com/USER/repository.git
git pull upstream pull/ID/head:BRANCHNAME
git checkout BRANCHNAME

Where USER is not your username but the original one (the one you forked from), ID is the pull-request id and BRANCHNAME will be the local branch name corresponding to the pull-request.

If you want to push to your own fork later, you will likely have to set the upstream (from BRANCHNAME):

git push -u origin BRANCHNAME
Holt
  • 36,600
  • 7
  • 92
  • 139
  • And use `pull --rebase` if you don't want your PR to include the upstream PR's changes as well. – Jans Rautenbach Mar 01 '22 at 11:16
  • I also had to do the following: ```git config pull.rebase false``` (to set me back into 'merge' mode). And then ```git config pull.ff true``` (vs "false" or "only" -- to allow fast-forwards again, but not require them). Hope it helps. – Paul Brady Mar 22 '23 at 15:13
3

See https://help.github.com/articles/checking-out-pull-requests-locally/:

git fetch origin pull/ID/head:BRANCHNAME
git checkout BRANCHNAME

where ID is the pull request number and BRANCHNAME is an arbitrary name for the new local branch.

Anders Kaseorg
  • 3,657
  • 22
  • 35
0

The GitHub API supports merging a pull request on the server using a PUT request. So, you may do a PUT locally and merge a pull request.

But note that this just means that a merge happened on the server. If you were on some branch, say master, and you remotely triggered a pull request, if you wanted the latest content you would still have to do a pull:

git pull origin master
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

Pull request is not a git feature it is a workflow and as such has to be followed if there is a need for replication. So the only way is to do the same locally.

git checkout featureA # as it has to be on origin
git checkout master/develop
git merge featureA

At this point you are in the state as the pull request.

Croolman
  • 1,103
  • 13
  • 40
0

Try this - do a

git pull

to ensure you have the latest changes in master, then while on the master branch, do a

git checkout <branch name >

to the desired that has the PR(pull request) and finally do a

git pull

while on that branch. I believe it should pull the current state of the brach that has a pull request.