[ master/main aliases update]

alias gpom="git push origin master"


alias gpom="git push origin master 2> /dev/null || git push origin main"

so that if no `master` branch exists in the present repo, is retries with `main` instead

· · Web · 2 · 2 · 3

that was actually not such a great solution as the error messages can get confusing: I replaced it by the following functions

git branch -r | sed 's|.*/||' | grep -E 'main|master' --color=never | uniq

git push origin $(git_main_branch_name)

@maxlath people may want to push HEAD's branch with :

alias gpoc='git push origin $(git symbolic-ref --short HEAD)'

@douginamug @jums I was reminded that there might be a simpler alternative but can we really trust a command without at least 3 pipes?!?

@maxlath @douginamug as i mistakenly created a "master" on a "main" repo. new proposition:

gcom () {
[[ "$(git branch -l main)" =~ [[main]]*$ ]] && git check-out main
[[ "$(gb -l master)" =~ [[master]]*$ ]] && gco master

main is the first if do avoid the mistake above. regex is here to ensure branch name is not preprended with "* " in case the user is already on the branch in question (the sed function on max proposition)
Im sure there more improvment to make :)

Sign in to participate in the conversation

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!