This has not been pretty in the past, but from Git 2.22 you can simply do:
$ git branch --show-current main