I have a set of git aliases that I use both in my personal life and also at my professional positions. Because of long-standing convention in git usage, I've hardcoded master
as a default "main" branch in many of these aliases.
However, I happen to be working at an institution where the convention is to use main
as the main branch. This means a lot of my aliases break when I try to use them, because I've hard-coded an assumption of a branch called master
, and and ensuant usage thereof.
Instead of changing the instances of master
in my aliases file, and maintaining separate versions of that alias file for different situations, I wonder if I can instead use a variable in my alias definitions, one that I could set in my .gitconfig
. Something like:
$ cat .gitconfig
...
[variables]
DEFAULT_BRANCH = main
[include]
path = myaliases.git
$ cat myaliases.git
bclean = "!f() { git branch --merged ${1-DEFAULT_BRANCH} | grep -v " ${1-DEFAULT_BRANCH}$" | xargs -r git branch -d; }; f"
Instead of
bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs -r git branch -d; }; f"