Yeah, not really looking for an answer. I have a decent idea, and I could guess. It's one of those things where when I find myself in that state, it means I messed something up. I google, read a few sentences, remember what it means and how to get to the state I want to be, and then move on with my life without committing the details to memory. It's one example of the confusing scenarios I find myself in with Git with more frequency than seems necessary. I'd rather debug a Kubernetes cluster.
Git does make a detached head sound like something is broken, but it's really just a nameless branch. Nothing broken about it. Any commits might become hidden, as all commits not in a branch are, but that's only after you move off the headless branch and git warns loudly about this.
I just tested to see what happens if you don't name a branch before leaving it. Surprisingly, despite all that scary looking text about detached head, if you switch over to another branch git will print out a message that you're leaving commits on an unnamed branch as well as instructions on how to get back and name it later (and of course the commit hash can also be recovered from the reflog).
So yeah not only is the detached head state not a broken state, it's not even really a scary state to be in.
For someone who understands git, it certainly is not. But if you are not aware of how git works, committing things when HEAD is detached could to confusion in the best case, and lost commits in the worst.
Comments
Yeah, not really looking for an answer. I have a decent idea, and I could guess. It's one of those things where when I find myself in that state, it means I messed something up. I google, read a few sentences, remember what it means and how to get to the state I want to be, and then move on with my life without committing the details to memory. It's one example of the confusing scenarios I find myself in with Git with more frequency than seems necessary. I'd rather debug a Kubernetes cluster.
Git does make a detached head sound like something is broken, but it's really just a nameless branch. Nothing broken about it. Any commits might become hidden, as all commits not in a branch are, but that's only after you move off the headless branch and git warns loudly about this.
I just tested to see what happens if you don't name a branch before leaving it. Surprisingly, despite all that scary looking text about detached head, if you switch over to another branch git will print out a message that you're leaving commits on an unnamed branch as well as instructions on how to get back and name it later (and of course the commit hash can also be recovered from the reflog).
So yeah not only is the detached head state not a broken state, it's not even really a scary state to be in.
For someone who understands git, it certainly is not. But if you are not aware of how git works, committing things when HEAD is detached could to confusion in the best case, and lost commits in the worst.