5

Is it possible to cherry-pick all pending PR from github?

Let's say I have 4 PR from 4 different forked repositories waiting for review. I need to apply all of them to the latest source code.

PR#65 Do something
PR#61 Notify this
PR#55 Fix that
PR#42 Show there

I know that I can git remote add all repositories and cherry-pick them one by one. However, I believe there would be easier/shorter way to cherry-pick all pending pull request which I don't know yet ;)

Thanks in advance

RNA
  • 1,164
  • 2
  • 19
  • 35

3 Answers3

5

in short:

add pr/* to .git/config


in detail:

Assume the repository is named test_repo

$ git remote -v
test_repo     http://github/testA.git (fetch)
test_repo     http://github/testA.git (push)

1. open git config

vim .git/config

2. add below line under [remote "test_repo"]

fetch = +refs/pull/*/head:refs/remotes/test_repo/pr/*

so it would look like

[remote "test_repo"]
url = http://github/testA.git
fetch = +refs/heads/*:refs/remotes/test_repo/*
fetch = +refs/pull/*/head:refs/remotes/test_repo/pr/*  <-- this line was added

3. "git fetch" will fetch PRs too

$ git fetch test_repo

 * [new ref]         refs/pull/16/head -> test_repo/pr/16
 * [new ref]         refs/pull/17/head -> test_repo/pr/17
 * [new ref]         refs/pull/18/head -> test_repo/pr/18
 * [new ref]         refs/pull/19/head -> test_repo/pr/19

4. now you can cherry-pick/checkout to PR #xx

git cherry-pick test_repo/pr/xx 
RNA
  • 1,164
  • 2
  • 19
  • 35
4

You can't cherrypick the commits because the commits are not in your local repository.

You should fetch the pull requests like that..

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

All at once: https://gist.github.com/piscisaureus/3342247

Philippe
  • 28,207
  • 6
  • 54
  • 78
1

What you need to do is pull each PR-branch one-by-one, resolve conflicts as required.

Given:

  - PR#65 at https://github.com/author_1/your-repo/tree/PR-branch-name-1
  - PR#61 at https://github.com/author_2/your-repo/tree/PR-branch-name-2
  - PR#55 at https://github.com/author_3/your-repo/tree/PR-branch-name-3
  - PR#42 at https://github.com/author_4/your-repo/tree/PR-branch-name-4

then pull each PR locally:
e.g. the PR#65:

git checkout <your-test-branch>
git pull https://github.com/author_1/your-repo.git PR-branch-name-1
ashmaroli
  • 5,209
  • 2
  • 14
  • 25
  • Use `git fetch`, not `git pull`, here, as `git pull` will `git merge` the pull request commit but the goal is to *cherry pick* rather than merging. (In general I commend not using `git pull` at all.) – torek Mar 23 '17 at 11:35
  • That technically true @torek. But since the OP is looking for easier/shorter way to have the PR commit(s) within the source code, `git pull` is the way to go as it will `fetch` the PR branch and `merge` all the commits in the PR in one go. – ashmaroli Mar 23 '17 at 12:44
  • 2
    That's the thing: he said, rather clearly, that he did not *want* them *merged.* – torek Mar 23 '17 at 13:03