Switching to main/master branch easily
Have you ever had this problem, when trying to do git checkout master
and receiving an error that such branch does not exist ? That's because some projects have switched to a new main
branch and other projects are too old and nobody is moving them to main
. Remembering which project is having which type of main branch was too much for me, so I have added following alias to my zsh:
function git_checkout_main_or_master {
git show-ref --verify --quiet refs/heads/master
if [ $? -eq 0 ]; then
git checkout master
else
git checkout main
fi
}
alias m=git_checkout_main_or_master
And now I just do m
in my terminal and git automatically switches me to the right branch.
Hope this helps someone besides me in the future :)