Get the name of default branch

Now that more repositories are using main, how to read the name of default branch during Travis builds? There is no such environment variable.

There accepted answer there is from 2017, when there was no hype with renaming master that required changes to git to be able to set the default branch. Is that really a recommended way in 2021?

What do you want to do? You asked how to get the default branch – I told you how to get the default branch. Default branch has been a feature in Git since its creation, nothing changed in the mechanism after the master → main renaming.

You told me to go look at the page with many answers, and I am asking which answer should I choose?

Whichever works for you the best.
E.g. some show the default branch for the local repo, others for a remote repo.