How to clone/download code from a pull request

I found a source code in github. It has some pull request which indicates the changing code. I would like to download/clone one of them to my PC. Its pull request id is 3983 at the address https://github.com/BVLC/caffe/pull/3983 Thank all

asked Feb 16, 2017 at 2:59 3,028 9 9 gold badges 39 39 silver badges 67 67 bronze badges Commented Feb 16, 2017 at 3:05

2 Answers 2

Because, someone has more one pull request, each pull request has own ID. How can I download correct version which corresponds to pull request ID

It is better to clone the original repo, and import the PR branch based on its ID

git clone https://github.com/BVLC/caffe cd caffe git remote add christianpayer https://github.com/christianpayer/caffe.git 

Then, for one of christianpayer's merged PR into origin:

git fetch origin pull/3983/head:pull_3983 git checkout pull_3983 

You can fetch other PRs from that remote repo, or add other remote repos for fetching other PRs.

1 1 1 silver badge answered Feb 16, 2017 at 5:38 1.3m 554 554 gold badges 4.7k 4.7k silver badges 5.5k 5.5k bronze badges

I tried your third command and I got the error "fatal: Couldn't find remote ref pull/3983/head Unexpected end of command stream".

Commented Feb 16, 2017 at 6:20

Yes, that is expected since the PR number exists only on origin repo: replace Christian payer by origin

Commented Feb 16, 2017 at 6:37

There are two ways to do this:

1:

git clone https://github.com/christianpayer/caffe.git cd caffe git checkout nd-cudnn 

It is from here:

2:

git clone https://github.com/BVLC/caffe.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to config

[remote "origin"] url = https://github.com/BVLC/caffe.git fetch = +refs/heads/*:refs/remotes/origin/* fetch = +refs/pull/*/head:refs/remotes/origin/pr/* 

Now fetch all the pull requests:

$ git fetch origin From github.com:joyent/node * [new ref] refs/pull/5190/head -> origin/pr/5190 * [new ref] refs/pull/5193/head -> origin/pr/5193 * [new ref] refs/pull/5198/head -> origin/pr/5198 * [new ref] refs/pull/520/head -> origin/pr/520 . 

To check out a particular pull request:

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