next(ref for ref in repo.remotes.origin.refs if ref.name == "origin/HEAD").ref.name
repo.remotes.origin.refs
will give you a list of the remote branches. Filter on the one that is the HEAD and check towards what it points(ref<.name>).
You are now left with something like "origin/master"
or "origin/main"
.