Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check out a GitHub pull request with git?

I'd like to check out a previously created pull request (created via GitHub web interface). I searched and found different places where a refs/pull or refs/pull/pr

But when I add fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to the git config file and do a git fetch

What I'm doing wrong? Should GitHub create automatically the pull/xyz stuff, or do I have to configure something?

like image 339
GarfieldKlon Avatar asked Dec 19 '14 14:12

GarfieldKlon


People also ask

How do you check out something on GitHub?

You can check out a remote branch using the git fetch –all command and then the git checkout command. A remote branch is a branch stored on the repository from which you fetch code.

Does git pull checkout?

Remember, all git pull does is run git fetch and then git merge (or git fetch and then git rebase ). It's the git checkout that is messing with the time-stamps on your work-tree files. Git doesn't really use or need the work-tree: that's for you.

How do I confirm a pull request?

To accept the pull request, click the Pull Requests tab to see a summary of pending pull requests. If you are happy with the changes, click Merge Pull request to accept the pull request and perform the merge. You can add in a comment if you want. Once you click Merge Pull request, you will see a button Confirm merge.


3 Answers

To fetch a remote PR into your local repo,

git fetch origin pull/$ID/head:$BRANCHNAME

where $ID is the pull request id and $BRANCHNAME is the name of the new branch that you want to create. Once you have created the branch, then simply

git checkout $BRANCHNAME

For instance, let's imagine you want to checkout pull request #2 from the origin main branch:

git fetch origin pull/2/head:MASTER

See the official GitHub documentation for more.

like image 126
timbo Avatar answered Oct 17 '22 06:10

timbo


This will fetch without you having to name a branch:

git pull origin pull/939/head

How do I get a specific pull request on my machine?

like image 40
3 revs, 2 users 90% Avatar answered Oct 17 '22 06:10

3 revs, 2 users 90%


I prefer to fetch and checkout without creating a local branch and to be in HEAD detached state. It allows me quickly to check the pull request without polluting my local machine with unnecessary local branches.

git fetch upstream pull/ID/head && git checkout FETCH_HEAD

where ID is a pull request ID and upstream where is original pull request has been created (it could be origin, for example).

I hope it helps.

like image 85
Andrew Ymaz Avatar answered Oct 17 '22 06:10

Andrew Ymaz