I have (amongst others) git aliases:
grm: git rebase mastergrim: git rebase -i masterThe development community as a whole is moving away from the use for master for the default branch, in favour of main. (For reasons relating to historical associations)
Unfortunately the community isn't doing that uniformly, and I frequently switch between projects, so I'd have to keep editing my aliases.
Is there any way to write the alias so that it interacts with "whichever of master or main exists in this repo"? (Happy to have it assume that only one of the 2 exists, locally)
I'd assumed that the solution would be something that "tries both options" in some way, but a solution that uses the linked question to determine the correct answer directly and then uses that answer would also work.
Use one of the answers from git - how to get default branch? to write an alias which looks up the correct branch name, then use that inside other aliases:
# ~/.gitconfig
[alias]
main-branch-name = "!f() { git symbolic-ref refs/remotes/origin/HEAD | sed \"s@^refs/remotes/origin/@@\" ; }; f"
rm = ! git rebase $(git main-branch-name)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With