Push current Git branch with git push -u origin HEAD

2019-08-29

If you try to do just git push a Git branch that is new and not in the remote yet, you get this message, which suggests that you need some extra arguments:

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

    git push --set-upstream origin new-branch

That command can be shortened with -u instead of --set-upstream:

git push -u origin new-branch

But it’s even possible to avoid typing the branch name by replacing it by the HEAD variable (if you are currently on that branch):

git push -u origin HEAD