Git has no concept of the main branch. Therefore what you want to do is not really possible.
Git users have a concept of the main branch and by general agreement among all git users (and general advice originally given by Linus Torvalds) this branch is normally called master but it does not have to be.
The reason the main branch can be given a name other than master is because git has no concept of the main branch.
Software created by other people such as Github or Bitbucket or Gitlab do have the concept of the main branch. If this is what you are asking you will need to use the APIs exposed by those software to find out which branch is the main branch. Of course you will need to know what service the developer is using in order to use its API.
For example for Github you can do this to get the main branch:
curl -H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/slebetman/httpstress |
grep default_branch
However, using git alone it is not possible to do what you want because the concept of a main branch is does not exist in git - it is only a concept in the human brains of programmers.