If you check out a commit instead of a branch:
git checkout abc123
…you're in detached HEAD: HEAD points directly at a commit, no branch attached. Commits you make here aren't on any branch — when you switch back, they become orphaned (and eventually garbage-collected).
The warning Git prints is real. Two safe escape hatches:
-
Throw away the work: git switch main. Detached commits drift into reflog.
-
Keep the work: create a branch first.
git switch -c new-branch
git switch main
git merge new-branch
If you've already switched away and need them back, git reflog will show the detached commits. Recover with git branch rescue <hash>.