git - show the current branch name

...or commit hash

December 12, 2024



Example:

$ git checkout -b feature_2025

# Show branch name
$ git branch --show-current
feature_2025

$ git rev-parse --abbrev-ref HEAD
feature_2025

$ cat .git/HEAD
ref: refs/heads/feature_2025

# Show branch commit hash
$ git rev-parse HEAD
901cd3ebbe115f32c74bff7432c829a7d14d1f23