Skip to main content

What is HEAD in Git?

HEAD is a pointer to the current commit you are working with.

How HEAD works

  • usually HEAD points to a branch (for example, main);
  • the branch, in turn, points to the last commit;
  • new commits are added wherever HEAD points.
HEAD → main → C5

Detached HEAD

HEAD can point to a specific commit, rather than to a branch:

  • this state is called detached HEAD;
  • commits made in this state do not belong to a branch;
  • such commits can be lost when switching branches.
HEAD → C3

Why HEAD is needed

  • it determines which branch you are currently working on;
  • it controls where the next commit will be written;
  • it allows moving through the project's history.

Short answer for an interview

HEAD is a pointer to the current commit or branch, defining the working state of the repository.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.