Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Git Tutorial 17 – What Is Head In Git?

Posted on 02/08/2025 By admin

As a part of GIT Tutorials End To End, we will learn about the HEAD concept of Git in this post.

I will expect that you are aware of the basic concepts and commands of GIT. But if you are a beginner in GIT then I strongly recommend you to refer GIT Basic Commands and Concepts section on my blog first.

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

We have seen the word “HEAD” in our previous posts but I was holding on this topic for a suitable time to make you understand better. Today is the time.

Let’s clone one of my public repo to practice and learn easily. The same repo I have used in my previous posts. In this repo, I have only the default branch “main” and two commits.

Observe the output of the git log command. It shows we have two commits in the repo. Newer commits are shown first. We also see HEAD -> main, origin/main, origin/HEAD with the second commit.

We know that when we clone a repo we get a hidden folder .git as well. It is the same folder when we run the git init command. This folder shows that a directory is a git directory and we can run git commands. Let’s go inside the .git folder and see its contents.

As soon as we changed the directory to the .git folder, the main changed to FIT_DIR!. If you remember it happens when we switch branches as shown in previous posts. Here it changed to just let you know that we are inside .git folder. The .git folder contains multiple files, folders and directories. You can see them explicitly in the file directory as well.

Ignore other files as of now and focus on a file named “HEAD”. Let’s see what is inside it. You can use UNIX command or explicitly open the file and see contents.

The HEAD file contains “ref: refs/heads/main“. In fact, it is storing a reference of another file which can be found at ref: refs/heads/main. “Main” is the currently checked out branch name here. If you switch to another branch then HEAD will contain “ref: refs/heads/“. We have another directory named ref inside .git folder.

Let’s go to the files pointing by HEAD i.e. refs/heads/main.

If you are good at Unix commands then we can use the below command instead of switching directory by directory.

We see some alphanumeric content here. Actually, it is nothing but the latest i.e. second commit id.

So HEAD indirectly points to the latest commit. If we create a new commit then HEAD will point to the latest commit.

There are multiple points to understand in the above commands.

  1. We can see the content of HEAD file is unchanged but its referenced file has latest commit i.e. 3rd commit.
  2. Observe output of git log command. Latest commit (3rd) shows HEAD -> main and just previous commit (2nd) shows origin/main, origin/HEAD. Earlier this commit i.e when we freshly cloned we saw all three together. Refer first screenshot in this post.
  3. When we cloned the repo, a local branch main which is same name as remote branch, is also created. At that time both local and remote branch was poniting to the same HEAD i.e. commit. With a new commit in local, HEAD of local main branch gets updated while HEAD of remote branch remained same old one as we have not puhsed our local change to remote repo.

Let’s push the new commit to remote and you can see HEADs of both local and remote are the same.

We can also use the git show HEAD command to see to which commit HEAD is pointing. It also shows the commit message and changes as part of the commit.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe to my YouTube channel.
#ThanksForReading
#HappyLearning

Uncategorized

Post navigation

Previous Post: Learn Selenium With Quiz 9 – Window Handle in Selenium
Next Post: Handling JQuery Dialog Box In Selenium Webdriver

Related Posts

Interview Questions – Make Selenium Easy Uncategorized
Generics In Java Uncategorized
September 1, 2018 – Make Selenium Easy Uncategorized
REST Assured Tutorial 18 – Querying RequestSpecification in Rest Assured Uncategorized
May 10, 2018 – Make Selenium Easy Uncategorized
learn with quiz Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark