The linked article Show archive.org snapshot found a simple way to rewrite legacy git aliases to make them work with differently named default branches
master
. Define it as the global init.defaultBranch
git configuration :git config --global init.defaultBranch master
# cd /path/to/project, then run:
git config --local init.defaultBranch main
~/.gitconfig
aliases to use the defaultBranch
variable, e.g.:[alias]
merge_request = push origin HEAD -o merge_request.create -o merge_request.target=master -o merge_request.draft
becomes
[alias]
merge_request = !git push origin HEAD -o merge_request.create -o merge_request.target="$(git config init.defaultBranch)" -o merge_request.draft
~/.bashrc
aliases to use the defaultBranch
variablealias gdm='git diff --color-moved=dimmed_zebra master'
becomes
alias gdm="git diff --color-moved=dimmed_zebra $(git config init.defaultBranch)"
Aliases are evaluated only once whenever you open a new terminal. This means that you cannot expect these aliases to adjust when you cd
from one project into another. You need to open a new shell in this case (or source
the ~/.bashrc
).