
Now, let's use the Git Checkout command to move our HEAD to commit B. We can view the history of commits using the following Git Log command. Suppose we have a single branch(called master) in our repository with just three commits(A - B - C). This way we will have a reference to these commits and we will not lose them.Ĭonsider the following scenario to better understand the concept of detached HEAD. A solution to this problem is to create a new branch based on these new commits.


This is proof that under normal circumstances the HEAD points to the currently checked-out branch. We can see in the image below that HEAD is pointing to the master branch( HEAD -> master). We can also use the Git Log command to view the last commit of our current branch. We can view the information about the commit to which the HEAD points by using the Git Show command. git/HEADĪs we can see in the image below, the file does not store any commit information but instead, it has the name of our currently checked-out branch(master in this case). We can view its content by using the Linux command cat(short for concatenate).

Git stores the information about the HEAD in the. The HEAD is automatically updated by Git if we add new commits to the current branch or we switch to a different branch.The branch itself is a pointer that references the last commit that was made on it.This is because the HEAD does not point directly to a commit but instead, it points to a branch. We can think of the HEAD as our current working branch.It is the last committed state of our project. As discussed above, the HEAD is a reference to the last commit of our current branch.The current checked-out branch is also known as the HEAD branch. In Git terminology, the HEAD is a pointer or a reference to the most recent commit of the currently checked-out branch.
