I want to know whether I'm in a "HEAD detached" state in a script.
Currently I parse the output of git status
but I dislike doing so because I've heard that it's a bad practice to parse Git output that's meant for human - I want a program-friendly interface to tell me whether HEAD is detached. I also don't want to manually look into .git/HEAD
or parse git description
or git branch
.
Any ideas?
git rev-parse --symbolic-full-name HEAD
, if it outputs HEAD, you're in detached mode, if it outputs a branch name, you're on that branch. – Optometristgit rev-parse --abbrev-ref HEAD
will give you a branch name if you're on a branch else will give you the detached HEAD hash – Pegpegagit rev-parse --abbrev-ref HEAD
gives just "HEAD" string for me, not a hash. – Maris