I am learning git and am following the excellent tutorials at http://gitimmersion.com.
In those tutorials, there is a blurb that tries to explain detached HEADs, and that states:
A “detached HEAD” message in git just means that HEAD (the part of git that tracks what your current working directory should match) is pointing directly to a commit rather than a branch. Any changes that are committed in this state are only remembered as long as you don’t switch to a different branch. As soon as you checkout a new branch or tag, the detached commits will be “lost” (because HEAD has moved). If you want to save commits done in a detached state, you need to create a branch to remember the commits.
A few questions on this:
- What exactly is a detached HEAD, and what conditions create it?
- Why is a detached HEAD pointing to a specific commit and not a branch?
- When you have a detached HEAD, do you always need to create a new branch to be able to commit/push the changes in it? Why/why not?
Thanks in advance!