git rev-parse --abbrev-ref HEAD

Category: Git - Core

git rev-parse --abbrev-ref HEAD

Print the current branch name

Resolves HEAD to the short branch name, like main, instead of the raw hash. On a detached HEAD it prints HEAD instead of a branch. It is the script-friendly way to ask which branch you are on.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.