Home

June 9, 2017, 1 min read

git push new branch

Git has changed its default push policy some time ago from 'matching' to 'simple', meaning that if you try to push a new branch for the first time, you will see this:

fatal: The current branch my-new-branch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin my-new-branch

Now of course you can change your push policy configuration, but maybe you want to retain that default behaviour and only override it explicitly for some cases? Then this may help you: We can get the name of the current branch using git rev-parse --abbrev-ref HEAD and thereby construct a simple command alias like this (gpn standing for 'git push new'):

alias gpn=git push --set-upstream origin `git rev-parse --abbrev-ref HEAD`