All fixes

Help, I am in “detached HEAD” state

HEAD points at a commit instead of a branch. Keep what you did on a new branch, or simply go back.

What Git says~/my-app
git checkout HEAD~1
Note: switching to 'HEAD~1'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

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

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 246fd15 Update header

The fix

  1. git switch -c experiment

    Creates a branch right where you are. Everything you committed while detached is now safe on it.

experiment is an example. Replace it with your own.

What happens to your historygit switch -c experiment
BeforeABCXmainHEAD
AfterABCXmainHEADexperiment

Why this works

Normally HEAD points at a branch, and every new commit moves that branch forward. After checking out a commit directly, HEAD points at the commit itself: you are on no branch. You can look around and even commit, but nothing holds on to those commits once you leave. Creating a branch gives them a name that does.