git checkout remote reference

git, github

Solution

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.

Problem

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 output like this: ``` * [new ref] refs/pull/1/head -> origin/pr/1/head * [new ref] refs/pull/1/merge -> origin/pr/1/merge * [new ref] refs/pull/10/head -> origin/pr/10/head * [new ref] refs/pull/10/merge -> origin/pr/10/merge * [new ref] refs/pull/11/head -> origin/pr/11/head * [new ref] refs/pull/11/merge -> origin/pr/11/merge ``` Now I want to checkout one of those refs. Nothing I try seems to work: ``` $ git checkout refs/pull/1/head error: pathspec 'refs/pull/1/head' did not match any file(s) known to git. ``` Or: ``` git checkout origin/pr/1/head error: pathspec 'origin/pr/1/head' did not match any file(s) known to git. ``` How can I checkout this reference?

Original source