How to stop yourself from accidentally switching to a git branch named "master" instead of "main"
October 02, 2021
If you have various projects which used either "main" or "master" as the main branch, and also have a remote which uses the other naming (e.g. heroku or another PaaS), you might find yourself accidentally switching to the wrong branch name and working on it. Here's how to inhibit that.
Put this in .git/hooks/post-checkout
if [ `git branch --show-current` == "master" ]; then echo "DO NOT USE MASTER" git checkout main git branch -d master fi
set it to executable:
chmod u+x .git/hooks/post-checkout
John Bachir's Code Blog