Review Github PRs Quickly

0
247

Github Pull Request Checkouts

If you’re like me, you like to find more efficient ways of doing something that is monotonous and time consuming. One of these things is checking out someone’s pull request on Github.com to review and test their code.

https://help.github.com/articles/checking-out-pull-requests-locally/ has a pretty nice tutorial. The problem is, you need to grab the ID number and then attach the remote repo as well as the new branch name:

git fetch origin pull/ID/head:BRANCHNAME

Improving The Process

If you go to the root of your repository (where the .git file is located), you can locate the config and open it in your favorite text editor:

vim .git/config

From here, you’ll want to locate the upstream remote in the config file, it may look like the following:

22     [remote "remote-name-here"]
23     url = https://github.com/upstream-remote-name/repo-name
24     fetch = +refs/heads/*:refs/remotes/upstream-remote-name/*

We will want to add one line to this block to look like the following:

22     [remote "remote-name-here"]
23     url = https://github.com/upstream-remote-name/repo-name
24     fetch = +refs/heads/*:refs/remotes/upstream-remote-name/*
25     fetch = +refs/pull/*/head:refs/remotes/upstream-remote/pr/*

This will auto-create branch names under the PR number of the pull-request we are checking out. pr/pr-number.

The last step is writing a simple bash script to checkout PR’s on the fly.

 co() {
     set $1
     git fetch upstream-name
     git checkout pr/${1##*/}
}

Now, any time we want to checkout a PR on the fly, we can simply run:

co https://github.com/Schachte/Git-Enforcer/pull/56

This will now automatically parse the pull request number and check out a new branch under pr/56

LEAVE A REPLY

Please enter your comment!
Please enter your name here