Last Updated: March 29, 2017
·
485
· 63ck0

Checkout pull request

When you manage project with many pull requests you need a fast way to test them despite continuous intergration.

I know two ways to do it.

By using Git CLI

$ git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"

Or if you want add it for all your repo at once

$ git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"

By editing manually .git/config

Edit .git/config and add fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to [remote "origin"] block.

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com:username/repo.git
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

Usage

Fetch all the pull requests:

$ git fetch origin
From github.com:username/repo
 * [new ref] refs/pull/1/head -> origin/pr/1
 * [new ref] refs/pull/1/head -> origin/pr/2
 * [new ref] refs/pull/1/head -> origin/pr/3

Now you can checkout a particular pull request:

$ git checkout pr/2
Branch pr/2 set up to track remote branch pr/1 from origin.
Switched to a new branch 'pr/2'

I have added this tip to Alzheimer repo, enjoy!