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?
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.
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.
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.
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.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With