I am working on a project which is maintained in Git, with a central repository on GitHub. I often review pull requests with the help of a local copy. While Git itself doesn't know anything about “pull requests”, GitHub makes the information available in a separate branch namespace. I've configured Git to fetch pull requests with a configuration like this:
[remote "origin"]
url = git@github.com:octocat/hello-world.git
fetch = +refs/heads/*:refs/remotes/origin
fetch = +refs/pull/*/head:refs/remotes/origin/pull/head/*
Then I can check out PR #42 with git checkout origin/pull/head/42
. So far so good.
If a pull request has been force-pushed after my initial review, I often want to compare the version that I reviewed with the new version. I would like to have something like origin/pull/head/42/1
referring to the latest commit before the first force-push, origin/pull/head/42/2
referring to the latest commit before the second force-push, etc. (I don't mind the exact names.) Is there any way to do this?
The problem has two parts:
- Get GitHub to tell me what the commit ID is for the pre-force-push tip of a pull request. This information appears on the web page (
https://github.com/octocal/hello-world/pull/42
says “… force-pushed themybranch
branch from COMMIT1 to COMMIT2”), but I can't find it in the API. - Teach Git that a certain commit should appear with a certain remote branch name, which may or may not be trivial depending on how (1) is done.
Is there a configuration or helper program that can give me easy access to old versions of GitHub pull requests, without having to copy-paste the commit ID from the web page and give it a local branch name?