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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With