Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Need An Account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question. Please subscribe to paid membership

Forgot Password?

Don't have account, Sign Up Here
Please subscribe to paid membership

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Quearn

Quearn Logo Quearn Logo

Quearn Navigation

  • Home
  • Sili AI
  • Quearn Drive
  • Quearn Academy
  • Guest Post (Lifetime Dofollow Backlink)
  • Blog
  • Free Guest Post Submission
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Sili AI
  • Quearn Drive
  • Quearn Academy
  • Guest Post (Lifetime Dofollow Backlink)
  • Blog
  • Free Guest Post Submission
Home/ Questions/Q 1006613
Next
Answered

Quearn Latest Questions

Ragini
  • 1
  • 1
RaginiProfessional
Asked: August 10, 20242024-08-10T19:38:50+05:30 2024-08-10T19:38:50+05:30In: Programmers

What is Detached HEAD?

  • 1
  • 1
detached head
  • 2 2 Answers
  • 268 Views
  • 0 Followers
  • 0

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. [Deleted User]
      Best Answer
      [Deleted User]
      2024-08-10T19:40:03+05:30Added an answer on August 10, 2024 at 7:40 pm

      If git was to rename detached HEAD I would have it named as a HEAD that isn’t identified by a branch and will soon be forgotten.

      We as people can easily remember branch names. We do git checkout new-button-feature / git checkout main. main and new-button-feature are easy to remember. And we can just do git branch and get a list of all branches. But to do the same with just commits you’d have to do git reflog which is very tedious. Because you have thousands of commits but only very few branches.

      A detached commit’s identifier is just its SHA. So suppose you checked out a commit (not a branch) i.e. you did git checkout d747dd10e450871928a56c9cb7c6577cf61fdf31 you’ll get:

      Note: checking out ‘d747dd10e450871928a56c9cb7c6577cf61fdf31’.

      You are in ‘detached HEAD’ state.

      …

      Then if you made some changes and made a commit, you’re still NOT on a branch.

      Do you think you’d remember the commit SHA? You won’t!

      git doesn’t want this to happen. Hence it’s informing your HEAD is not associated to a branch so you’re more inclined to checkout a new branch. As a result below that message it also says:

      If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:

      git checkout -b


      To go a bit deeper a branch is built in a way that it’s smart. It will update its HEAD as you make commits. Tags on the other hand are not meant to be like that. If you checkout a tag, then you’re again on a detached HEAD. The main reason is that if you make a new commit from that tag then given that that commit is not referenced by anything (not any branch or tag) then still its considered a detached HEAD.

      Attached HEADs can only happen when you’re on a branch.

      HEAD is a pointer, and it points — directly or indirectly — to a particular commit:

      Attached HEAD means that it is attached to some branch (i.e. it points to a branch).

      Detached HEAD means that it is not attached to any branch, i.e. it points directly to some commit.

      To look at from another angle, if you’re on a branch and do cat .git/HEAD you’d get:

      ref: refs/heads/Your-current-branch-name
      

      Then if you do cat refs/heads/Your-current-branch-name then you’d also see the SHA of the commit that your branch is pointing/referencing to.

      However if you were on a detached HEAD you and cat .git/HEAD you’d just get the SHA of the commit and nothing more:

      639ce5dd952a645b7c3fcbe89e88e3dd081a9912
      

      By nothing more I mean the head isn’t pointing to any branch. It’s just directly pointing to a commit.


      As a result of all this, anytime you checkout a commit (without using the branch name to checkout), even if that commit was the latest commit of your main branch, you’re still in a detached HEAD because your HEAD is not pointing to any of your local branches. Hence even checking out a tag will put you in a detached HEAD. To add onto that, even checking out a remote branch that you have fetched into your computer would result in a detached head ie git checkout origin main would also end up as a detached head…

      Summary

      All of the following will cause detached head:

      • checkout any commit
      • checkout any tag
      • checkout any remote branch

      You’re only on an attached head, if you’ve checked out a local branch

        • 2
      • Stevemark
        Stevemark Scholar
        2024-08-10T20:33:58+05:30Replied to answer on August 10, 2024 at 8:33 pm
        This answer was edited.

        If you are working in your repo and do git checkout <SHA> you will be in a “detached HEAD”. You are not on a branch (the commit is likely to be on multiple branches). You are checked out to a specific instance in the history.   A detached head can also occur when you are rebasing. You are checked out to a specific commit.   You would need to create a branch in order to commit/push changes because you would be creating commits that would be “in limbo” with no way to identify them other than the SHA. Git will remove the commit during its garbage collection because of it not being on a branch.   Checkout the “Detached Head” Section on this page for more in depth information: http://git-scm.com/docs/git-checkouthttp://git-scm.com/docs/git-checkout

          • 1

    Sidebar

    Stats

    • Questions 10k
    • Answers 10k
    • Best Answers 3k
    • Users 224k
    • Popular
    • Answers
    • priya

      The header length of an IPv6 datagram is _____.

      • 3 Answers
    • Quearn

      How to approach applying for a job at a company ...

      • 7 Answers
    • priya

      In the IPv6 header,the traffic class field is similar to ...

      • 3 Answers
    • Quearn
      Quearn added an answer What Makes Quearn’s Guest Post Service Special? ✅ Permanent Placement –… May 19, 2025 at 6:03 am
    • Anonymous added an answer B. dns resolver May 9, 2025 at 4:37 pm
    • Anonymous added an answer A.CAS May 9, 2025 at 4:37 pm

    Top Members

    Stevemark

    Stevemark

    • 185k Points
    Scholar
    Ragini

    Ragini

    • 76k Points
    Professional
    Lark Davis

    Lark Davis

    • 16k Points
    Pundit
    prasanjit

    prasanjit

    • 5k Points
    Teacher
    rohit

    rohit

    • 1k Points
    Begginer

    Trending Tags

    answer computer current data diode education electric flux igbt machine magnetic mcq network poll power quearn question scr study voltage
    Сollaborator

    Latest News & Updates

    • Quearn Support

      Smart Cities: Integrating Drones and Autonomous Vehicles

    • Quearn Support

      Water Wars: How Scarcity Is Shaping Global Politics

    • Quearn Support

      Carbon Footprint 101: What It Is and Why It Matters ...

    • Quearn Support

      Cramming and Stress: How All-Nighters Affect the Brain and Body

    • Quearn Support

      What is procrastination: The Hidden Psychology Behind Delaying Tasks

    Explore

    • Home
    • Add group
    • Groups page
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges
    • Users
    • Help

    Footer

    Quearn

    About

    Quearn is a social questions & Answers Engine which will help you establish your community and connect with other people.

    About Us

    • Blog
    • About Us
    • Contact Us
    • Become a Partner in Quearn
    • Free Guest Post Submission
    • Question Categories
      • AI
      • Analytics
      • Artificial Intelligence
      • Backlinks
      • Blockchain
      • Communication
      • Company
      • Cryptocurrency
      • Education
      • Internet
      • Language
      • Programmers
      • Science
      • SEO
      • University

    Legal Stuff

    • Terms & Conditions
    • Privacy Policy
    • DMCA Policy
    • Cancellation & Refund Policy

    Help

    • Support
    • FAQs
    • Guest Posting
    • Careers
    • Liberty Wire

    Follow

    © 2018-2025 All Rights Reserved by Quearn