I'm aware of How can I check out a GitHub pull request?
While adding fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
to .git/config
does allow fetch and checkout, pull actions fail:
[remote "origin"]
url = https://github.com/the/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
Fetch and checkout work fine:
$ git fetch origin
... all good
$ git checkout -b "pr-123" origin/pr/123
Branch pr-123 set up to track remote branch pr/123 from origin.
Switched to a new branch 'pr-123'
... success, got the code!
But pull fails:
$ git pull
Your configuration specifies to merge with the ref 'refs/heads/pr/123'
from the remote, but no such ref was fetched.
... failed.
I can specify the ref manually:
$ git pull origin refs/pull/123/head
and this works. But how can I configure the config file so that:
- fetch & checkout still work, and
- subsequent pull actions work without manually specifying the remote ref?
I have found that if I edit the config file and change:
[branch "pr-123"]
remote = origin
merge = refs/heads/pr/123
to:
[branch "pr-123"]
remote = origin
merge = refs/pull/123/head # <-- here is the change
... then git pull
works fine. How can this be achieved without manually editing the config file for every pull request?
pull
does not work. I have added the config file bit to the question, maybe there is something wrong there? – Coincidenceorigin/pr/123
worked for you, there should be no such ref for PR (maybe you have a remote branch with this name?). Tryrefs/remote/origin/pr/123
. When you do fetch, this is what you should see getting fetched. – Bipetalousrefs/remote/
makes the checkout command fail. Fetch results look like this:* [new ref] refs/pull/123/head -> origin/pr/123
... I'm tempted to start up a virtual machine and make a screencast :) – Coincidence