4

What is the difference between the Git HEAD and tip?

Sorry if this has been asked somewhere else.. haven't seen any other questions on this.

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
  • The Git `HEAD` points to the tip of the current branch _except_ in the detached HEAD state, in which case it points to the commit which you just checked out. – Tim Biegeleisen Sep 28 '16 at 16:10
  • Possible duplicate of [What is HEAD in Git?](http://stackoverflow.com/questions/2304087/what-is-head-in-git) – Don Branson Sep 28 '16 at 19:42

1 Answers1

8

From gitglossary (probably accessible via git help glossary on computers with git installed.):

branch
A "branch" is an active line of development. The most recent commit on a branch is referred to as the tip of that branch. The tip of the branch is referenced by a branch head, which moves forward as additional development is done on the branch.

head
A named reference to the commit at the tip of a branch. Heads are stored in a file in $GIT_DIR/refs/heads/ directory, except when using packed refs. (See git-pack-refs[1].)

HEAD
The current branch. In more detail: Your working tree is normally derived from the state of the tree referred to by HEAD. HEAD is a reference to one of the heads in your repository, except when using a detached HEAD, in which case it directly references an arbitrary commit.

With two definitions of "head," differentiated by capitalization, there does seem to be room for confusion. But a quick summary appears to be:

A tip is the most recent commit on a branch. There is one tip per branch.

A head (all lowercase) is somewhat like a tag in that it's a conveniently named reference to the tip of a branch. Unlike a tag, a head will automatically change which commit it references when you add a commit to a branch. There is one head per branch.

The HEAD (all uppercase) is whatever commit you currently have checked out. There is only one HEAD.

Community
  • 1
  • 1
8bittree
  • 1,769
  • 2
  • 18
  • 25
  • Upvoted, but NB for readers: The `HEAD` is not a commit itself. It can be a reference to a `head`, or can point to a specific commit(in this case, it's a "detached HEAD"). Also note that many people use the term 'branch' to mean 'head' in the Git glossary. It seems that Git does not define the terms very rigorously, so learners should be careful. – starriet May 04 '23 at 02:19