HEAD in git perspective
Head in the domain of git basically refers to a pointer mechanism used by git to do what it does.
What is git?, what is it used for?
Git is a solution to a problem which we might have confronted one way or the order, it can be considered as the ultimate Version Control System.
Version control system, well this is a system that maintains changes to a file or set of files over time. You probably have had the need to do this when working on files in the past.
Back to git, it is the most popular Version control system in the world, it was developed by Linus Torvalds in 2005 and is an actively maintained open source project (“Amazing how the best things in life are free”). Git is a DVCS (Distributed Version Control System) what that means that you are able to share the base of your file history and not limit it to a single fixed location, thereby making sharing and collaboration easy and seamless.
Its a not so complicated thing to talk about, but the functionalities would take a loooong to comprehensively list out, but one thing that kind of stands out is the ability of git to record different version of your file(s), this is done on each commit (a git command), which basically captures the state of your file(s) at that moment and documents it. This gives you the ability to go back to any state already captured.
This brings us to “HEAD”, in the git perspective, this is a resource or mechanism used by git to enable it perform this already mentioned cool function.
Head can be related to the pin head of a vinyl record player, the player uses this pin head to determine where exactly it is reading from on the record, this is also the function of the HEAD in git. But as you would already observed, Git is not limited to sequential traversal, that is , its selection of states is not limited to next track or next instance, it can be assigned to any of the already captured state. This is what gives Git the power to return your application to any state.
When a commit is made, a hash is created, and then the head is placed on the most recent hash, that is the HEAD points to the most recent hash, eg, commit1, commit2, commit3, after these three commits, the HEAD would point to “commit3".
Because of the complex functionality of Git, such as rolling back to immediate previous version, future versions, or moving multiple steps forward or backwards, it is necessary that at all times Git knows exactly which hash it is pointing to, so it knows in what relation it is to perform certain tasks when a specific hash is specified in the command.
Unlike an array, which is serial, Git is able to make jumps from any point to any other point, therefore a store of the latest position is necessary, that is which particular hash or most recent hash is Git working on.
Git Head is the mechanism with which Git is able to keep track of its current position.The importance of HEAD in Git cannot be overemphasized, most of the complex operations performed on Git are depended on this simple but and yet integral part of Git.