Head in Git

Abdul Jabbar Mar 29, 2022
  1. What is HEAD in Git
  2. Difference Between head and HEAD
  3. Use git show HEAD to Check Status of the HEAD
Head in Git

Mostly in our Git documentation, the head refers to the top of the Git repository, called the HEAD of the repository. But still, the question is that what exactly is the HEAD in Git?

In this article, we will learn about Git HEAD, but before that, let’s have a quick look at what Git is and what it is used for.

Git is a convenient tool used for distributed control systems; it is used by developers and software engineers, and data scientists, who use Git to manage the source code development of their program and its history to create the results based on that data.

What is HEAD in Git

While working with Git, we can check out only one branch at a time, called the HEAD branch. We can also call it the Active or Current branch in that repository.

HEAD is a pointer that points towards the initial point of the current branch in the repository in a lifecycle of a repository. When we check out another branch, HEAD changes its point to the currently checked-out branch.

We can also say that it is considered the last checked-out point in a repository or that it will be the parent of the next commit we do in the future. The current HEAD is used locally for every repository and is separate for each developer in a team.

Every head is indicated by its name; it can be a branch name, a tag name, etc. The Head in each repository is called master as default.

A repository is based on any number of heads. Specifically, a single head is referred to as the current head.

This head is aliased to HEAD, always written in capital letters. Git always notes this current branch in a file located in the Git repository in .git/HEAD.

If we wonder what exactly this file contains, we will use the command mentioned below to see the HEAD pointer using the below command.

$ cat .git/HEAD
ref: refs/heads/master

The mentioned commands show a local branch named as the master is the repository’s latest current HEAD.

  1. It shows us the contents of .git/HEAD.
  2. ref: refs/heads/master
  3. It shows us the reference to the current committed branch that we checked out and points to the commit at the initial point of the latest branch.

Difference Between head and HEAD

A head, written in lowercase, is known as any of the named heads in the current repository. In contrast, HEAD, written in uppercase, refers specifically to the currently active head of the repository.

Use git show HEAD to Check Status of the HEAD

The command used to check the status of the Head is git show head. It will show us the location of the Head. Below is the syntax to run the command in Git.

Syntax:

$ git show HEAD
Author: Abdul Jabbar
Abdul Jabbar avatar Abdul Jabbar avatar

Abdul is a software engineer with an architect background and a passion for full-stack web development with eight years of professional experience in analysis, design, development, implementation, performance tuning, and implementation of business applications.

LinkedIn

Related Article - Git Head