upvote
The use of init.defaultBranch here is really problematic, because different repositories may use a different name for their default, and this is a global (your home directory scope) setting you have to pre-set.

I have an alias I use called git default which works like this:

  default = !git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'
then it becomes

  ..."$(git default)"...
This figures out the actual default from the origin.
reply
I have a global setting for that. Whenever I work in a repo that deviates from that I override it locally. I have a few other aliases that rely on the default branch, such as “switch to the default branch”. So I usually notice it quite quickly when the value is off in a particular repo.
reply
This is a great solution to a stupid problem.

I work at a company that was born and grew during the master->main transition. As a result, we have a 50/50 split of main and master.

No matter what you think about the reason for the transition, any reasonable person must admit that this was a stupid, user hostile, and needlessly complexifying change.

I am a trainer at my company. I literally teach git. And: I have no words.

Every time I decide to NOT explain to a new engineer why it's that way and say, "just learn that some are master, newer ones are main, there's no way to be sure" a little piece of me dies inside.

reply
Why does your company not migrate to one standard? Github has this functionality built in, and it's also easy enough to do with just git.

I'm personally a huge fan of the master-> main changejus5t because main is shorter to type. Might be a small win, but I checkout projects' main branches a lot.

reply
This is a good one you should contribute it to git extras.
reply