Git aliases using arbitrary default branch names

I have a very simple git alias which shows me what's changed on my feature branch compared to the main branch (which is probably what I'm about to target with a PR/merge):

  [alias]
      ld = diff master

This only works if "master" is the name of the default branch in your current repo, and this is decreasingly common.

  % git ld
  fatal: ambiguous argument 'master': unknown revision or path not in the working tree.

One solution is to call git symbolic-ref on the "origin" remote HEAD.

  % git symbolic-ref refs/remotes/origin/HEAD
  refs/remotes/origin/plague

This is just swapping one assumption for another though: I'm now assuming that there's a remote named origin instead of a branch named master. However, that assumption holds true (for me) everywhere, and seems likely to be true more often than the default branch being named master.

Here's what that bit of my .gitconfig looks like now:

  [alias]
      ld = "!git diff $(git symbolic-ref refs/remotes/origin/HEAD | awk -F '/' '{print $4}')"