Skip to content

Rebase and merge a fork pull request to master

florrain edited this page Nov 5, 2014 · 4 revisions

Rebase and merge a fork PR


*/!* Be sure to only push when you are done and sure of your rebase. Don't rebase on master or you'll see terrible things happening around you.

If you want to revert to the beginning:
$ git branch master
$ git reset --hard remotes/origin/master
$ git branch -D the-fork-branch

And then restart from step 2.


  • Add remote (only first time)
    $ git remote add the-fork-remote [email protected]:anotheruser/responsys-api.git

  • Fetch everything from the remote
    $ git fetch the-fork-remote

  • Branch the changes
    $ git checkout the-fork-remote/feature-branch

  • Rebase on master
    $ git rebase master

  • Find the commit that is base of the PR. IOW the commit from where the branch has been created.
    $ git merge-base the-fork-remote/feature-branch master

  • WITH THE RESULT, go into interactive rebase
    $ git rebase —-interactive ${HASH}

You should see all the commits that are part of the PR branch in a list. Let's edit the list to that:

reword 1fc6c95 do something #change the first commit message to be explicit. Example below.
fixup 6b2481b do something else #merge this commit to the upper one
fixup dd1475d changed some things #merge this commit to the upper one
fixup c619268 fixing typos #merge this commit to the upper one

fixup deletes the commit log message and insert the commit content into the previous one to make only big one commit. reword instead of pick allows to rename the commit message. The rebase will ask for the new message after saving the first screen just as if you were creating a new commit. Let's update the PR commit message to : [PR] Desc of the feature.

As a result of this rebase, there will be only one commit : 1fc6c95 [PR] Desc of the feature

  • Push the new commit to the origin remote
    $ git push origin master
Clone this wiki locally