‘What the HEAD is and how important it is’ GIT and GIT HUB 101

Your local repository consists of three “trees” maintained by git. The first one is your *Working Directory* which holds the actual files. The second one is the *Index* which acts as a staging area and finally the *HEAD* which points to the last commit you’ve made. It’s generally simplest to think of it as HEAD is the snapshot of your last commit.

A while back I was working with Github when I ignorantly decided to edit the file name of the repository files. Yes, It happened so fast. How easy it was until I made a point of pushing another file from git bash. *Detached HEAD*. That error is quite scary because it prompted me to try all manner of make-it-work procedures to push this file that was supposed to be on repo before the deadline. Then I saw this command, git push origin -force master, please don’t try the command at home. Unless you are sure of what it does. It actually overwrites all the files in the repo with the one being pushed. Dangerous right? So it happened to me, BAM! and my world toppled. That prompted me to get to know the importance of this HEAD. Yes, after losing my files.

The HEAD is important as it helps you keep track of commits. You could return to a previous commit, reattach a detached HEAD, do a soft reset and a hard reset.
So I recovered from the fatal error by creating a new branch and running git reflog show, then git branch newbranch HEAD@{1} and I was good to go.