Saturday, June 18, 2016

CheckOut a Pull Request in Git

Set-Up your Local Git Config

Locate the section for your github remote in the .git/config file. It looks like this:
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url =
Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url =
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

Use the Command Line to Checkout a Pull Request

Now fetch all the pull requests:
$ git fetch origin
 * [new ref]         refs/pull/1000/head -> origin/pr/1000
 * [new ref]         refs/pull/1002/head -> origin/pr/1002
 * [new ref]         refs/pull/1004/head -> origin/pr/1004
 * [new ref]         refs/pull/1009/head -> origin/pr/1009
To check out a particular pull request:
$ git checkout pr/999
Branch pr/999 set up to track remote branch pr/999 from origin.
Switched to a new branch 'pr/999'

Use Source Tree to Checkout a Pull Request

First, fetch all the open Pull Requests:

Then, simply right click the appropriate Pull Request and select Checkout.


No comments:

Post a Comment