3

Initial Understanding

HEAD

  • "indicates the head of the current branch."
  • so, there is only one HEAD.

head

  • refers to the most recent commit of any branch.
  • "...the most recent commit (or "head") of a branch..."
  • so, there are as many heads as there are branches.

tip

  • refers to the most recent commit of any branch.
  • so, tip is synonymous with head

Please correct me if I'm wrong. Also, please provide documentation on the usage of "tip".

New Understanding after Reading Answer

Each branch points at a commit. The head (or tip) is the commit at which a branch points. If there are ten branches then there are ten heads and ten tips!

HEAD is a "you are here" marker that points at a commit in one of two ways: most of the time, HEAD points to a branch which in turn points at a commit; other times, HEAD points directly at a commit. The latter is called detached HEAD.

Quotes are from git(1)

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467

1 Answers1

4

Branches (a.k.a. branch heads) mark points of interests in your repo. The metaphor isn't perfect, but you can think of branches as some sort of "bookmarks". Each branch points to a commit; that commit is called the tip of the branch.

HEAD (note the uppercase) is different. It usually points to a branch, indicating which point of interest in your repo you're currently at. However, in some cases, HEAD may also point directly to a commit (in which case your repo is said to have a "detached HEAD").

You can think of HEAD as

  1. a "you-are-here" marker on the metro map that is your commit graph; or
  2. an indicator of which branch (if any) is currently checked out.

For instance, in the following repository, the tip of the master branch is the commit of abbreviated ID f42c5; the tip of the develop branch is the commit of abbreviated ID 190a3; HEAD points to master, indicating that master is currently checked out.

enter image description here

jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • [The docs](http://git-scm.com/docs/git-commit) say that `git commit --amend` lets us: "Replace the tip of the current branch by creating a new commit." Could it just as well say, "Replace HEAD by creating a new commit?" – Shaun Luttin Sep 25 '14 at 23:43
  • No, not really. You don't "replace" `HEAD`; rather, you make it point to another commit. To get a better idea of what amending a commit means, see http://stackoverflow.com/questions/25948049/git-commit-amend-in-detached-head-state/25948372#25948372 – jub0bs Sep 25 '14 at 23:46
  • Why would HEAD usually point to a branch not to a commit? The docs say that it "indicates the head of the current branch," and that head refers to the most recent commit. Ergo HEAD ought to refer to the most recent commit of the current branch. – Shaun Luttin Sep 25 '14 at 23:47
  • 1
    Great. I think I understand: 1. branches point at commits, 2. head (aka tip) is the commit at which a branch points. 3. HEAD points either to a branch (which points to a commit) or directly at a commit (in detached HEAD situations). – Shaun Luttin Sep 26 '14 at 00:02
  • @ShaunLuttin Yes; that's it. – jub0bs Sep 26 '14 at 00:02
  • 2
    Nitpicking for future beginners) @ShaunLuttin's comment could be edited to make it more clear: 1. branch 'head's point at commits, 2. "tip" is the commit at which a branch 'head' points. 3. HEAD points either to a branch head (which points to a commit) or directly at a commit (in detached HEAD situations). – starriet May 04 '23 at 02:35