open core »

Check out Github pull requests

This is a quick way to checkout Github pull requests into a local branch so you can test if everything is ok.

Just create this simple function in your ~/.bashrc or ~/.zshrc file:

function checkout-pr() {
    git fetch origin refs/pull/$1/head:PR$1

After saving, just reload your shell and the checkout-pr command should be available.

To use it just enter a project’s folder and type:

$ checkout-pr 13

This will access your project’s origin, fetch the content of the pull request with ID 13 and save it in a local branch called PR13.

Now you can checkout the PR13 branch and evaluate the changes made.