Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rebase a GitHub pull request on top of my newer local commits

Suppose I am locally on the branch master of our blessed repository. Someone has sent in a pull request.

How do I apply the commits of that pull request on top of my local branch - as if those commits were rebased on my branch - in a single command?

Note: the pull request is several days old, and my local branch has new commits since the pull request has been created.

like image 640
Geoffrey De Smet Avatar asked Jun 26 '13 08:06

Geoffrey De Smet


1 Answers

There's a great blog post on the subject, from Igor Zevaka

You first have to fetch the hidden pull request ref, and place it under the pr/NNN remote branch:

git fetch origin refs/pull/1234/head:refs/remotes/pr/1234

(replace 1234 by the pull request number)

After this it's just a classical rebase: checkout the pull request, and rebase it on your master branch:

git checkout pr/1234
git rebase master

or alternatively

git rebase master pr/1234

You might of course see conflicts.

Now the pull request is rebased on master, and is the current branch. If you want to update master just merge the pull request (we say --ff-only because we know it'll be a fast-forward merge):

git checkout master
git merge --ff-only pr/1234

To have a one-liner some shell aliasing is required, it's just a matter of scripting :)

like image 61
CharlesB Avatar answered Oct 03 '22 01:10

CharlesB