How to get branch name in git

There are three basic ways to get branch name in git.

Use git name-rev.

~/repoone$ git name-rev HEAD
HEAD main

Use git branch.

~/repoone$ git branch
* main
  maincopy
  maintemp
  source
  sourcecopy
  target

Use git symbolic-ref.

~/repoone$ git symbolic-ref HEAD
refs/heads/main