I have a list of pull requests on github. I can fetch the pull requests like this:
git fetch origin +refs/pull/*:refs/remotes/origin/pr/*
I get
The first command (git checkout refs/pull/1/head
) didn't work because refs/pull/1/head
is the name of the reference in the remote repository. You don't have a reference with that name in your local repository because your fetch
refspec translated it to refs/remotes/origin/pr/1/head
.
The second command (git checkout origin/pr/1/head
) should have worked, although it should have given you a "detached HEAD" warning. Was there a typo that you fixed when posting your question to Stack Overflow?
Your fetch
refspec told git to translate the remote references into local references in the refs/remotes
directory. The references in that directory are treated specially -- they're "remote references" meant to indicate the state of the remote repository the last time you did a fetch
. Normally you don't want to check those refs out directly -- you want to create a local branch that is configured to "follow" or "track" the remote reference (which enables special convenience shortcuts such as the @{u}
revision parameter and easier push
/pull
usage).
Try:
git fetch origin +refs/pull/*:refs/remotes/origin/pr/*
git checkout -b whatever-branch-name-you-want origin/pr/1/head
The above creates a new local branch called whatever-branch-name-you-want
(I recommend calling it pr/1/head
) pointing at the same commit as origin/pr/1/head
, configures whatever-branch-name-you-want
to track origin/pr/1/head
, then switches to the new branch.