Suggest an editImprove this articleRefine the answer for “What is HEAD in Git?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**HEAD in Git** is a pointer to the current place in the commit history, that is, to the commit you are currently working with. **Key point:** HEAD shows "where you currently are" in the repository.Shown above the full answer for quick recall.Answer (EN)Image**HEAD in Git** is a **pointer to the current place in the commit history**, that is, to the commit you are currently working with. Simply put: **HEAD shows "where you currently are" in the repository.** --- ## What exactly HEAD points to In a normal situation: - HEAD points to the **current branch** - the branch points to the **last commit** - so HEAD indirectly points to **the last commit of that branch** The chain looks like this: ``` HEAD → main → last commit ``` --- ## Understanding it with an example If you are on the `main` branch and make a new commit: - the commit is added **to the end of the branch** - the `main` branch moves forward - HEAD **stays on the** `main` **branch** --- ## Detached HEAD Sometimes HEAD can point **not to a branch, but directly to a commit**. This is called **detached HEAD**. For example: ```bash git checkout a1b2c3d ``` In this case: ``` HEAD → commit a1b2c3d ``` Important for an interview: - commits made in detached HEAD **do not belong to a branch** - if you do not create a branch, they can easily be lost --- ## Why HEAD is needed at all HEAD is needed so that Git knows: - which state to take files from - where to add new commits - which version of the project to show in the working directory --- ## How to see HEAD ```bash git status ``` Shows the current branch (so that is where HEAD points). ```bash git log --oneline --decorate ``` Shows where HEAD and the branches are in the history. --- ## A frequent candidate mistake Wrong: "HEAD is the last commit" Correct: **HEAD is a pointer** that usually points to the last commit of the current branch, but not always.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.