For scripting, hide errors with --quiet and use --short to simplify ("refs/heads/X" prints as "X")

git symbolic-ref

  • Read, change, or delete files that store references.
    More information: <https://git-scm.com/docs/git-symbolic-ref>.
  • Trick copyright: tl;dr; <https://github.com/tldr-pages/tldr>

git symbolic-ref --quiet --short refs/{{name}}

click the source code to copy install git symbolic-ref on any operating system with command-not-found.com