Are you tired of git NOT just pushing your branch and instead first asking to set origin for every new branch ?

Well, here is a command that can help you:

git push 2>&1 >/dev/null | tail -2 | grep 'git push' | awk '{split(\$0,a,\" \"); print a[5]}' | xargs -I{} git push --set-upstream origin '{}'

What this will do is first try `git push` and if there is an error it will get branch name and run .

of-course you are not going to write (or even copy past this every-time) so, what you can do is just create a shortcut (alias) for it. Something like this:

alias gph=”git push 2>&1 >/dev/null | tail -2 | grep ‘git push’ | awk ‘{split(\$0,a,\” \”); print a[5]}’ | xargs -I{} git push — set-upstream origin ‘{}’”



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store