Read more

Force GitHub Pull Requests to update the diff against its target branch

Arne Hartherz
December 12, 2012Software engineer at makandra GmbH

When you have a Pull Request on GitHub that includes commits from another Pull Request, you will still see them after the "child" PR has been merged. Unfortunately, GitHub won't automatically update the diff (or commit list).

Illustration book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

Here is what worked for me:

  1. Check out the target branch
    1. git checkout my-target-branch
    2. Make sure you are up to date against origin (e.g. git fetch and git status). You should be 0 commits ahead or behind.
  2. Add and commit a file
    1. touch .please-update
    2. git add .please-update
    3. git commit -m "Force PR update"
  3. Push
  4. Do a hard reset to the state before adding above file:
    ^
    git reset --hard HEAD~
  5. Push that state again to production with a forced push:
    ^
    git push --force origin my-target-branch

That will make GitHub update the diffs on all Pull Requests going to that branch.

Important: While this works nicely for integration branches, you probably do not want to do this for master or other high-traffic branches.
In that case, you can do the above for your source branch (the one that's being merged into master). Obviously, only the PR of that branch will be updated, but may just be enough.

This feels clumsy, but it seems there is no way to make GitHub do this nicely. :( If you know of a better approach, please let me know.

Posted by Arne Hartherz to makandra dev (2012-12-12 10:50)