6

I'm maintaining a legacy GitHub repo now and there is a lot of abandoned PR into old branches. For example, I work in the v3.5 branch now, and PRs are for 3.3 and older.

How can I effectively merge them into my new branch if they target older ones?

In case it's important, I'm sure there will be no conflicts.

I found some old questions about similar things, but I can't find any info on how to do it via GitHub. Is there still no functionality on that? Do I have to manually do it via git?

Piotr Niewinski
  • 1,298
  • 2
  • 15
  • 27
s1ddok
  • 4,615
  • 1
  • 18
  • 31
  • How are the branches created? All branched from the master? Or is 3.5. branched from 3.3. for example? I find it strange to have PRs into version branches and not into master. – crackmigg Mar 06 '16 at 18:32
  • @migg unfortunately there is no master historically there. 3.4 was branched from 3.3 and so on. The latest branch is playing master role. So now I'm in 3.5 and want to merge all PRs from 3.4-. – s1ddok Mar 06 '16 at 19:06
  • Does this answer your question? [Merge pull request to a different branch than default, in Github](https://stackoverflow.com/questions/9135913/merge-pull-request-to-a-different-branch-than-default-in-github) – Metro Smurf Aug 15 '22 at 14:14

3 Answers3

3

On the github.com pull-request page there is a link to "command line instructions". If you like to do it manually the steps are:

  • Create a new merge-branch off the PR target branch. Checkout the merge-branch. Pull the PRs by hashes or head refs into the merge-branch.
  • Merge the merge-branch into your new target branch by pull, merge, or cherry-pick.

A little bit more searching found this page about renaming branch on github website. It suggests:

  • Set default branch to your old-target branch. Create a branch off your old-target branch with a different name.
  • Merge the PRs to the old-target branch. Rename the old-target branch to something different.
  • Rename your other new branch to the old-target branch name.
Community
  • 1
  • 1
minghua
  • 5,981
  • 6
  • 45
  • 71
1

All of the pull requests are saved here

pull/ID/head

You can check out s pull request locally by

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

if you want all pulls you can add to the fetch ref

This is a read only address. Is you can't push back to it up update the pull request

Remote name is the local git name for the remote

These are shown by git remote -v

exussum
  • 18,275
  • 8
  • 32
  • 65
  • It seems like this can help me, but I don't really understand your question. What exactly this is going to allow me to do? – s1ddok Mar 07 '16 at 08:00
  • And what is the branchname? Is this my current branch, or is this PR's target branch? Or is PR's own branch? – s1ddok Mar 07 '16 at 08:05
  • branch name is the name of a new local branch to reference this pull request. eg `git fetch oldGit pull/1234/head:old-pull-1234` – exussum Mar 07 '16 at 09:21
  • Actually you confused me even more with that naming. Assuming `A` is the current branch that I want PR to merged into, `B` is the original PR's target branch, `ID` is PR's id and `C` is PR author's branch name, what exactly should I put into that commands? – s1ddok Mar 07 '16 at 17:45
  • Do you want me to merge PR into old branch firstly? – s1ddok Mar 07 '16 at 17:46
  • git fetch oldGit pull/ID/head; git merge FETCH_HEAD assuming your currently on A and git remote -v shows oldgit poitig to the old repo address – exussum Mar 07 '16 at 21:56
1

Since the old branches are probably not needed, you can just merge the pull request to the old one (as originally requested in the pull request) and then create a new pull request from the old one (e.g. 3.3) into the new one (e.g. 3.5).

yorammi
  • 6,272
  • 1
  • 28
  • 34