Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Git Tutorial 18 – What Is A Detached Head In Git?

Posted on 03/16/2025 By admin

As a part of GIT Tutorials End To End, we will learn about the Detached 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.

I will also strongly recommend you to Lean about HEAD in git first to understand the detached head properly.

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 three commits.

We can represent the above status of the repo using the below diagram-

We know that a branch is a pointer to a commit as we can see above. If we add a new commit in a branch then the branch will point to a new commit and HEAD will be updated as well to point to the new commit. This is an ideal situation.

We also know that a commit is a point that shows the status of your repo at that point. With every commit, your repo will have an updated version. Git provides us to jump to any commit directly. Remember when we switch to any specific commit then you will see repo status as per that commit only.

To checkout a specific commit we can use the below command-

git checkout

We can use some starting characters of a commit id instead of a complete commit id. You can use git log –oneline command to see short commit ids.

Before checking out a specific commit

Checkout first commit

Now you are in a detached head. Now you are not in any branch but in a specific commit and HEAD is no more pointing to a branch name like ideal condition.

From the above command, you can see that you are in a specific commit now and HEAD is moved to that commit instead of the main branch. We have created a file FileA as part of the first commit and the same state we can see now. When we move into a detached head state, git let us know with all possible options. You can modify the repo state in a detached head.

You can get out of a detached head state anytime by switching to a branch. You can use “git switch ” or “git checkout ” to switch to a branch. Please note git switch is a newer command introduced in Git 2.23 version.

Let’s check out to first commit and add and commit files.

To keep commits in the detached mode we need to create a new branch. You can use the git checkout command to create and switch to it as well as discussed here.

We can see we are no more in a detached HEAD.

Now you can merge the new branch to the main branch.

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: How To Launch Firefox Browser in Selenium WebDriver – Java
Next Post: How To Raise Or Log A Defect With All Required Fields In Testing

Related Posts

Postman Tutorial Part 41 – Dynamic Variables in Postman – Make Selenium Easy Uncategorized
October 2019 – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
Selenium Topics – Page 7 – Make Selenium Easy Uncategorized
Postman Tutorial Part 18- Sharing & Importing Collections as a Link in Postman Uncategorized
DuplicateIn2DArray – Make Selenium Easy 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