I need to pull in a specific pull request (that hasn\'t been processed into the main stream yet) in the NServiceBus repo:
https://github.com/johnsimons/NServiceBus/c
git pull origin pull/28/head
Or
git fetch origin pull/28/head:28
git checkout 28
Can I pull a not-yet-merged pull request?
To fetch a pull into your repository:
git fetch git@github.com:jboss/jboss-common-beans.git refs/pull/4/head
Then do whatever you want with FETCH_HEAD:
git checkout -b new-branch FETCH_HEAD
below is to make your 'git fetch' command to fetch all pull requests when run "git fetch"
add below into ~/.gitconfig
[remote "origin"]
fetch = +refs/pull-requests/*/from:refs/remotes/origin/pr/*
note the reference "refs/pull-requests/" has the stash naming convention, for git hub, you may need different format
You can do this:
1) Add the upstream remote:
git remote add upstream git@github.com:Particular/NServiceBus.git
2) After that, you can checkout any pull request to a new branch per its ID:
git fetch upstream pull/PULL_REQUEST_ID/head:NEW_BRANCH_NAME
Then you'll have a branch named NEW_BRANCH_NAME
containing the PR code.
If you do this as often as me, you may want to setup some aliases for it. I have this in my .gitconfig:
[alias]
fetch-pr = "!f(){\
[ -z \"$1\" ] && { echo Usage: git fetch-pr PULL_REQUEST_ID [REMOTE_NAME] [NEW_BRANCH_NAME]; exit 1; }; \
remote=${2:-origin}; \
branch=${3:-pr-$1}; \
git fetch $remote \"pull/$1/head:$branch\"; \
}; f "
pr = "!f(){\
branch=${3:-pr-$1}; \
git fetch-pr \"$@\"; \
git switch $branch; \
}; f "
With the above, I can do:
git fetch-pr 123 # fetch PR #123 into branch pr-123
git fetch-pr 123 some-branch # fetch PR #123 into some-branch
git pr 123 # fetch and switch to the branch
This is the solution from GitHub docs:
From your project repository, check out a new branch and test the changes.
git checkout -b GithubUserID-branchName branchName
git pull https://github.com/GithubUserID/reponame.git branchName
Where:
GithubUserID
is the username of the person who opened the pull request.branchName
is the name of the branch for example masterreponame
the repository name like demo-todoExample :
git checkout -b felix123-master master
git pull https://github.com/felix123/demo-todo.git master
See this help article from GitHub: https://help.github.com/articles/checking-out-pull-requests-locally