Git: Rebase a Pull Request without access on the Fork

Pavlos-Petros Tournaris
2 min readMay 30, 2016

--

So the other day a friend of mine, wanted some help with Git. The goal of our mission was to have a rebased Pull Request without having to bother the author of the Pull Request, at the end of the day.

Generally, before submitting a Pull Request, you rebase with the upstream master branch, so that if there were more changes between your fork and the upstream’s master, at the time that you are about to submit your contribution, they will be rebased. This would mean that we would have less conflicts and a readable commit history :)

But there was a problem in our case. The author of the aforementioned Pull Request did not rebase his master branch with the upstream’s master branch before submitting the Pull Request. We also could not contact him to let him know about the issue and help him fix it.

So what could we do on such a case considering all of the above?

Searching Google was not of much help. We could not find something specific about it. I could also not find an option like this on Github’s page, in case there was already something built-in, that would solve this problem.

The solution I came up was pretty much straight forward. If you can not access the Fork , then bring the Fork’s code into your repository.

So, we created a new branch with an appropriate name, that would reveal its purpose. After that we saw that we could directly pull from a remote into the checked-out branch.

What is the advantage of this though?

Doing that would give us the ability to access the exact same code that the Pull Request included. This would give us the direct ability to rebase locally with the original repository.

After pulling from the remote we now had a branch with the changes. We then issued a git rebase master and applied the new changes on top of the master’s latest commits. After that we want to force push the new image of the branch on our remote branch, so we issue a git push -f. The next and last step was to checkout into master and issue a git merge — no-ff branch_with_changes_from_pull_request

And that was it, we now had the same changes from the original Pull Request without having to bother the author of it, in order to rebase his Fork and re-submit his Pull Request.

Please do not forget to give the appropriate credits to the original author of the Pull Request after doing that. Although the commit messages will still show the original author if you have done everything correctly :) I am pretty sure that there is a more l33t way of achieving the same result, but you know this is a solution as well :)

Hope you enjoyed the article and stay tuned for more :)

--

--