Updated Mon, 29 Aug 2022 05:31:37 GMT

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

I want git push origin to automatically set the upstream reference when I push a locally-created branch for the first time.

I know about git push -u, but I don't want to have to think about whether or not I've used -u before or otherwise set an upstream reference. In other words, I want git push to automatically have the effect of git push -u on any push of a branch that doesn't already have an upstream.

Is this possible? If it requires an alias or utility script, that's fine.


Today I came across (a new?) option "push.autoSetupRemote". git config help says:

If set to "true" assume --set-upstream on default push when no upstream tracking exists for the current branch; this option takes effect with push.default options simple,
       upstream, and current. It is useful if by default you want new branches to be pushed to the default remote (like the behavior of push.default=current) and you also want
       the upstream tracking to be set. Workflows most likely to benefit from this option are simple central workflows where all branches are expected to have the same name on
       the remote.

Comments (2)