Checking Out Pull Requests with Stash and Github

The day Jeremy Edgell, a co-worker at Classic, mentioned it was possible to checkout pull requests, I knew that this trick would greatly increase my code review efficiency. Jeremy's solution involved adding an additional reference to the pull request location in an individual git repo's .git/config file. You can see a similar example to Jeremy's Stash solution in this gist.

Checking%20out%20a%20Github%20pull%20request Checking out a Github pull request (Note: The git alias, gpr-origin, indicates the remote to reference. I have one setup for origin and upstream.)

While I appreciate this capability, I didn't like the idea of having to change the git config of each repo I use. While reading about alternative solutions, I found this Atlassian blog post. Under the heading "Fetch a single pull request using refs", a really great solution exists for setting up pull request checkout capabilities for Stash and Github repositories in the global ~/.gitconfig file. I really appreciate the ingenuity of this solution!

If you review the gists below, you will see my modified git aliases for global .gitignore file, along with examples for executing each pull request checkout. I modified the Stash alias (spr) to fetch pr/<pr#>/from and pr/<pr#>/merge branches. The alias then checks out the pr/<pr#>/from branch. Once the alias executes successfully, it is possible to diff against the pr/<pr#>/merge branch to see exactly what will be merging when the pull request is merged. This really helps speed up a code review process, since all code can be reviewed and diff'd locally.

The Github alias (gpr) is setup to fetch the pull request and checkout the pr/<pr#> branch. Github doesn't appear to provide a merge branch like Stash, but it is always possible to diff against the branch that the pull request is set

Blog Category: