How to configure git push to automatically set upstream without -u?

You can configure it with git config using git config --global push.default current.

Docs: https://git-scm.com/docs/git-config/#Documentation/git-config.txt-pushdefault


Since I don't think this is possible using git config, here is what you can do in bash:

[[ $(git config "branch.$(git rev-parse --abbrev-ref HEAD).merge") = '' ]] && git push -u || git push

If the current branch has a remote tracking branch, it calls git push otherwise it calls git push -u


Note: the fact that the new default push policy "simple" relies on a branch having an upstream one means that:
setting an upstream branch is viewed as a voluntary step, not an hidden automated one

When "git push [$there]" does not say what to push, we have used the traditional "matching" semantics so far (all your branches were sent to the remote as long as there already are branches of the same name over there).

We will use the "simple" semantics that pushes the current branch to the branch with the same name, only when the current branch is set to integrate with that remote branch.
There is a user preference configuration variable "push.default" to change this.


So building up from mechanicalfish's answer, you can define an alias, with the right double quotes (") escaped (\"):

git config alias.pu "![[ $(git config \"branch.$(git rev-parse --abbrev-ref HEAD).merge\") = '' ]] && git push -u || git push"

git pu origin

Sc0ttyD proposes in the comments the following alias:

alias gpu='[[ -z $(git config "branch.$(git symbolic-ref --short HEAD).merge") ]] && git push -u origin $(git symbolic-ref --short HEAD) || git push'

In multiple lines:

alias gpu='[[ -z $(git config "branch.$(git symbolic-ref --short HEAD).merge") ]] && 
           git push -u origin $(git symbolic-ref --short HEAD) || 
           git push'

I've had the same problem. I've found this alias (.gitconfig)

[alias] track = "!git branch --set-upstream-to=origin/`git symbolic-ref --short HEAD`"

Usage: git track once per new branch (currently checked out). Then just push as normal :)