If your git branch is in detached head state and you want to know the branch name of this detached head state, this is a simple solution for you.
cd into your git project directory and run the command.
git branch --contains HEAD
This way you can find the correct branch of your git project dir.
In above screenshot, head is detached from branch branch-two.
If user wants to know the branch name from where head was detached, above command is the solution.
You can see in the above screenshot that we can find the detached head branch using above command.