3. Move a pull request to a different branch

Last updated by Steve Clay

It's often necessary to move a pull request to a different branch.

Let's say you have a branch 1234 and you need to move it from 2.x to 1.12. I have two separate Elgg installed for these branches in ~/www/elgg-2.x/ and ~/www/elgg-1.12/.

There's probably a git rebase solution for this, but I find it easy enough to cherry-pick the commits onto a new branch. First I do a git log and copy the SHAs of the commits I want to apply in reverse order:

cd ~/www/elgg-1.12/
git remote add local_2x ~/www/elgg-2.x
git fetch local_2x

Now my 1.12 repository has all the commits in my 2.x repository. I just recreate the branch on 1.12 and cherry-pick over:

git checkout 1.12  #just to make sure
git checkout -b 112_1234
git cherry-pick SHA  #SHA is the commit SHA I'm copying
git push -u fork 112_1234  #fork is my forked Elgg repo on GitHub

Now I go to https://github.com/Elgg/Elgg and GitHub helpfully gives me the option to create a new pull request on my shiny new 112_1234 branch. I then go into the old pull request and close it after linking to the new one.