How to apply unmerged upstream pull requests from other forks into my fork?
Update: Via Webpage
You can also do this via the github webpage.
I assume, you should have already a fork (MyFork
) of the common repo (BaseRepo
) which has the pending pull request from a fork (OtherFork
) you are interested in.
- Navigate to the fork (
OtherFork
) which has initiated the pull request which you like to get into your fork (MyFork
) - Go to the pull requests page of
OtherFork
- Click new pull request
- The pending pull request(s) should be offered. Remember to select proper
OtherFork
branch too. Select on the left side as the base fork your fork (MyFork
) (IMPORTANT). - Now the option of
View pull request
should change toCreate pull request
. Click this.
Now you should have a pending pull request in your fork (MyFork
), which you can simply accept.
You can do it manually quite easily:
add the other fork as a remote of your repo:
git remote add otherfork git://github.com/request-author/project.git
fetch his repo's commits
git fetch otherfork
You have then two options to apply the pull request (if you don't want to choose pick 1.)
If you don't care about applying also the eventual commits that have been added between the origin and the pull request, you can just rebase the branch on which the pull request was formed
git rebase master otherfork/pullrequest-branch
If you only want the commits in the pull request, identify their SHA1 and do
git cherry-pick <first-SHA1> <second-SHA1> <etc.>
Like Tekkub said previously, you can just pull the branch in directly. Most of the time with GitHub, the branch is simply "master" on the requesting User's fork of the project.
Example: git pull https://github.com/USER/PROJECT/ BRANCH
And as a pratical example:
Say you forked a github project called safaribooks and there is the following pull request, in the originating project, that you want to put in your fork:
Then, in your fork's cloned project folder, run:
git pull https://github.com/fermionic/safaribooks.git fix-str-decode
Pull requests for the project may come from many different authors (forks), and you probably don't want a separate remote for each fork. Also, you don't want to make any assumptions about the branch the author used when submitting the pull request, or what else might be in the author's master branch. So it's better to reference the pull request as it appears in the upstream repository, rather than as it appears in the other forks.
Step 1:
git remote add upstream <url>
You've probably already done this step, but if not, you'll want a remote defined for the upstream project. The URL is the clone URL of the project you forked. More info at Configuring a remote for a fork and Syncing a fork. upstream
is the name you are giving to the remote, and while it can be anything, upstream
is the conventional name.
Step 2:
git pull upstream refs/pull/{id}/head
... where {id}
is the pull request number. upstream
is the name of the remote to pull from, i.e. just "upstream" if you followed step 1 exactly. It can also be a URL, in which case you can skip step 1.
Step 3:
Type in a commit message for the merge commit. You can keep the default, although I recommend giving a nice one-line summary with the pull request number, the issue it fixes, and a short description:
Merge PR#42, fixing VIM-652, support for mapping arbitrary IDEA actions