-2

In Git's terminology, is origin a ref or something else?

Is it correct that origin is defined as a configure variable remote.origin.url in a configure file such as .git/config?

Must a ref be a file for example .git/refs/heads/*? If yes, can origin still be a ref?

halfer
  • 19,824
  • 17
  • 99
  • 186
Tim
  • 1
  • 141
  • 372
  • 590
  • 1
    The word "reference" is not defined in the terminology document you linked to. Are you using that word interchangeably with "ref" or something? – David Grayson Jan 16 '19 at 01:25
  • Some relevant info here: https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches – sakura-bloom Jan 16 '19 at 01:25
  • 1
    It is a `remote`. A remote is a repository whose branches you track. A remote has some properties like `url`, `pushurl`, `fetch`, `push`, etc. These properties are defined as `remote.origin.url`, `remote.origin.pushurl`, etc. A ref can be a file or an entry in `.git/packed-refs`. – ElpieKay Jan 16 '19 at 03:12
  • 1
    https://stackoverflow.com/a/9529518/6309 – VonC Jan 16 '19 at 05:55

1 Answers1

3

Short answer: origin is a string of six characters. Whether it has any meaning anywhere depends on the "anywhere".

Longer answer: yes, origin is a ref or something else.

OK, that's not long enough, so let's go a bit longer:

  • Some Git commands look for a remote. When you run git clone, if you don't use the -o option, you get a remote named origin, so:

    git remote show
    

    will list origin. That's a valid remote.

  • Some Git commands look for a commit specifier or a tree specifier or similar. Here, if you use a string of letters that cannot be mistaken for a hash ID, Git will go through the six-step resolution process outlined in the gitrevisions documentation. I'm not going to quote that documentation here, but note that one of the six steps looks to see if refs/remotes/name/HEAD exists. If origin is a valid remote, and git fetch has run in the usual way, there is almost certainly a valid refs/remotes/origin/HEAD that translates to a valid commit hash ID.

Hence origin is a valid form of ref-name, when Git tries to use it as one. It's also a valid remote, when Git tries to use it as one.

Note that some Git commands look for both remote names and commit specifiers. In that case, origin can be used in both positions and have both meanings:

git push origin origin:newbranch

for instance. The first origin is a remote and the second is a ref.

torek
  • 448,244
  • 59
  • 642
  • 775