Welcome to another enlightening edition of TWIL, the series dedicated to fostering continuous learning in the ever-evolving landscape of software development. This week, join Katie as she navigates the trail of Git aliases with default branch complexities. Her insights dive into creating adaptable Git aliases amidst the shifts from "master" to more inclusive terms like "main" or "primary," streamlining your Git workflow with precision and inclusivity. Save time and prevent hiccups by harnessing her tips to refine your Source Control Management practices, ensuring your Git experience stays ahead of the curve.
Git aliases with default branch
Git aliases that assume that your default branch is called "master" can be problematic (for example; having "develop" as the default branch, or the industry shift to "main", "primary". etc., etc.)
default = "!f() { git remote show ${1:-'origin'} | grep 'HEAD branch' | sed 's/.*: //'; }; f"
Some other aliases that build off of this one that I've found helpful:
cd = "!f() { git checkout $(git default); }; f"
rd = "!f() { git rebase $(git default); }; f"
up = "!f() { git remote update origin && git pull origin ${1:-$(git default)}; }; f"
update = "!f() { git cd && git up && git co - && git rd; }; f"
- git