2

In Arch Linux packaging, I encountered the term git tip (What is a branch tip in Git?). As a git user, I became used to call a HEAD what I consider to be the same or at least a similar concept.

What is the relationship between the two? Why are there two names for the same thing (assuming they are) and are there circumstances where one name is more appropriate?

2 Answers 2

8

HEAD is a special term in git. It refers to the most recent commit at the moment, and at the place in the graph you are sitting right now.

If you are in a branch, and at its tip, then the branch tip is also known as HEAD.

If you check out another branch, then that branch's tip becomes HEAD.

If you check out a random commit that is not a branch tip at all, e.g.

git checkout HEAD~3 

(which as likely as not will put you into a detached-head state), then that commit is known as HEAD, though it does not necessarily line up with any branch's tip.

Sign up to request clarification or add additional context in comments.

Comments

2

This is a question closely related to the Git model itself: all commits (with the exception of the initial commits) have at least one parent:

 +--- G + A +- B +- C +- D +- H + + +----|--- E | +--- F 

which means that all the commit can be considered as nodes of a directed acyclic graph, where initial commits are the roots; the leaves of this directed acyclic graph are the branch tips.

Re HEAD, from git(1):

Named pointers called refs mark interesting points in history. A ref may contain the SHA-1 name of an object or the name of another ref. Refs with names beginning ref/head/ contain the SHA-1 name of the most recent commit (or "head") of a branch under development. SHA-1 names of tags of interest are stored under ref/tags/. A special ref named HEAD contains the name of the currently checked-out branch.

This description doesn't apply so well in detached HEAD scenarios (since the branch doesn't really have a name), but it still describes it very well, if you think of that situation as an anonymous branch.

In short, HEAD is a pointer to a commit (in a manner of speaking - it's generally more accurate to think of HEAD as a pointer to a ref, which in turn points to a commit), whereas branch tips refer to a specific type of commit, those with no descendants.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.