THE HEAD AND ITS IMPORTANCE IN GIT

Version control is a system that records changes to a file or set of files over time. Using version control is like making snapshots of files at different times after making changes on the files. Every checkout on a project is a full backup of all its data.

Git as a system in version control has three main states that describe the processes. These states are namely: committed, modified and staged states. The modified states shows files that have been modified after previously adding them to the staging area. Staged states shows tracked files that are in the staging area and ready to be committed, while commit state is when files have been saved or stored.

Different branches of the project or working directory could be created while working in git. Whenever a commit is made, the HEAD points to that last commit on the current branch. The HEAD is like a pointer that tells which branch is the current branch. (see figures below)

Fig. a. master is the current branch

It points to the current and most recent commit in that branch. When you switch to a different branch, the HEAD changes and points to the tip of the new branch.

Fig. b. testing is the current branch

The tip of the new branch is the most recent commit of that branch. However, if the HEAD points to a commit which is not the last commit on a branch, then we have a detached HEAD.

IMPORTANCE OF THE HEAD
  • The HEAD tells which branch is the current branch.
  • It makes it easy to reset or move to a previous commit.
  • It is an important pointer that makes switching/ rolling back to a different version very easy.
  • It saves the crashing or loosing of the whole project when things go wrong, since it helps in rolling back to previous snapshots.
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.