gitgithubgit-refspec

git refs/pull/... vs. pull/


In various places, looking for instructions on how to create a local branch from a GitHub Pull Request, I have seen two versions:

git fetch upstream refs/pull/PR_ID/head:NEW_LOCAL_BRANCH

and

git fetch upstream pull/PR_ID/head:NEW_LOCAL_BRANCH

My question is, what's the difference between including "refs" in the address, and not including it?
Both seem to work fine.


Solution

  • what's the difference between including "refs" in the address, and not including it?

    Including it gives a reference that works, directly.

    Not including it means that Git has to figure out what you mean. It does that by trying stuff. One of the first things it tries is to put refs/ in front of what you said — and by golly, that works.


    (For a recital of the full procedure that Git uses to figure out what you mean, see

    https://git-scm.com/docs/gitrevisions

    Look at the third entry under Specifying Revisions.)