Tibor's Musings

Local Handling of GitHub Pull Requests

If a project uses GitHub repository and receives many pull requests coming from many developers, it is not necessary to add remote repository for every developer to one's local checkout in order to work with pull requests locally. By tweaking one's .git/config one can automatically receive all upstream pull requests as remote upstream/pr branches.

As an example, let's take Invenio project whose upstream usually points to git@github.com:inveniosoftware/invenio.git. If one edits .git/config of the local checkout to add a new "pull" line to the fetch directive in the following way:

[remote "upstream"]
    url = git@github.com:inveniosoftware/invenio.git
    fetch = +refs/heads/*:refs/remotes/upstream/*
    fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*

then running the usual git fetch upstream will now regularly bring all pull request updates:

$ git fetch upstream
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 13 (delta 1), reused 6 (delta 1)
Unpacking objects: 100% (13/13), done.
From github.com:inveniosoftware/invenio
   b0b9220..17054ee  pu         -> upstream/pu
 + 63c7c21...0ec9487 refs/pull/1744/head -> upstream/pr/1744  (forced update)
   e3a98eb..cdf4e16  refs/pull/1765/head -> upstream/pr/1765
 + bd7e369...b030ec4 refs/pull/1807/head -> upstream/pr/1807  (forced update)

so that one can do the usual:

$ git log master..upstream/pr/1744 --stat

to inspect, test, review, cherry-pick, amend, merge and otherwise work with the pull request #1744 locally, without having to add the individual developer repository as remote.

(Thanks to Jiří Kunčar for the tip.)

git