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