Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git clone pull request instead of master branch

Tags:

git

github

How can I git clone the PR which haven't been merged by the author in github? Tried to fork a repo but the pr is gone.

like image 857
Charles Jr. Avatar asked Sep 16 '25 00:09

Charles Jr.


2 Answers

clone then fetch that PR to a local branch. For example:

git clone https://github.com/mimblewimble/grin
git fetch origin pull/2932/head:pr2932
git checkout pr2392

Note:

  1. replace https://github.com/mimblewimble/grin with your source repo
  2. replace 2932 with your source Pull Request number
  3. replace pr2932 with your desired branch name

I was looking for a single command to clone a single branch of a PR, but it seems not exist (please let me if somebody know that trick).

like image 169
gary Avatar answered Sep 17 '25 15:09

gary


By "clone the PR", I assume you mean: "having my local clone of the project at the state of a given PR".

You clone a repository, not a Pull Request. Git itself has no notion of Pull Request. However, the Pull Request is probably associated with a branch, so you can do:

git clone url/of/your/repo destinationDirectory
cd destinationDirectory
git checkout branchOfThePR

If you already have a clone, then, as @JB Nizet said, you need to fetch the new branches:

git fetch remoteName

Then you can check the branch out:

git checkout branchOfThePR
like image 33
padawin Avatar answered Sep 17 '25 14:09

padawin