Git and its HEAD

Published Dec 16, 2017
Git and its HEAD

GIT and its HEAD

Git is a Source code Management and Version Control System that enables developers to better organise and maintain their code. It was developed by Linus Torvalds in 2005 when developing the Linux kernel. Back in the days before Git, developers had a tough time maintaining code or working together on a single project simultaneously. Nowadays there are several different Online Git services like:
Github .
Bitbucket .
Gitlab e.t.c .

Git is usually operated with standard commands through a command terminal but most of the Git systems available today have a GUI desktop client that allows the full utilization of Git without even knowing the commands. The standard commands used to operate a Git include:

*git clone (to create a working copy of a repository)

*git add (to updates the index using the current content found in the working tree).
*git pull (to pull a remote repository).
*git commit (to commit changes to a file).
*git push (to push edited repository back to the master ).
*git branch (to create a snapshot of a working repository).
*git merge (to merge the branch to the master repository).
*git status (to check the status of a repository wether it is edited or not).


The head is simply a reference to a commit object. Each head has a name. By default, there is a head in every repository called master. A repository can contain any number of heads. At any given time, one head is selected as the “current head”. This head is called to HEAD (in capitals).

The HEAD as the most recent commit to a branch is very important because it signifies the most recent changes made to that branch.

You can think of the HEAD as the tip of the “current branch”. When you switch branches with git checkout, the HEAD revision changes to point to the tip of the new branch. It is possible for HEAD to refer to a specific revision that is not associated with a branch name. This situation is called a detached HEAD.

The Detached HEAD
The HEAD in a Git determines your current working revision(and thereby the files that are placed in your project’s working directory). Normally, when checking out a proper branch name, Git automatically moves the HEAD pointer along when you create a new commit. You are automatically on the newest commit of the chosen branch.

When you instead choose to check out a commit hash, Git won’t do this for you. The consequence is that when you make changes and commit them, these changes do NOT belong to any branch.

Discover and read more posts from Ibrahim Abdulkadir
get started