I noticed recently that I’ve (almost) never used a local
master branch in Git. I only use it in simple one-off playground repos that I don’t plan to support and never in professional development or in “serious” pet-projects.
So, is it really required?
I’d say: it’s mostly useless to have a local
main branch in Git. I’ve googled and found this article by Alec Benzer and totally agree with what he said, but let me put it my own post.
Most probably your Git workflow forbids any pushes in the
main branch on the server: it is either updated by pull requests or by a team member with special access permissions (“gatekeepers”). So, you rarely push your local
main to its remote counterpart. Moreover, you’ll need to keep it in sync with the remote
main or it will become stale. Extra work with no profit!
Every time you need a
origin/main (assuming your remote is
origin), just don’t forget to
fetch the latest remote state.
E.g. starting a new branch from main:
git checkout -b branch origin/main
Checking the difference between any branch and the latest
git diff origin/main branch
Rebasing you branch on the latest
git rebase origin/main branch
You can even checkout to the latest main without really checking out any branch:
git checkout origin/main
You’ll appear in a detached
HEAD state and won’t be able to commit. Some tools like
gradle-release plugin won’t work, but, hey!, do you really want to release from a local checkout?
Thanks for reading to the end. May your merges be conflictless!