DEV Community

anjushaKhandavalli
anjushaKhandavalli

Posted on

Auto setup remote branch with push.autoSetupRemote

Whenever you create a new branch and trying to push the new commit then you will start seeing this error:

Error message while pushing the first commit to new branch<br>

After this we often run:
git push — set-upstream origin <branch-name>

To get rid of doing this every time, git from version 2.37.0 gave us a configuration field called “push.autoSetupRemote” . More about this on git words :-)

push.autoSetupRemote

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.

In simple words to push the current branch and set the remote as upstream automatically every time you push, setting push.autoSetupRemote to true in git config once, is enough.

To do this just run this command in terminal:

git config --global --add --bool push.autoSetupRemote true

Enter fullscreen mode Exit fullscreen mode

Then git push will automatically setup the remote branch.

Note: The --global flag means this will apply to all git commands on your machine (regardless of which repo it is), you can omit the flag to make it specific to a single repo on your machine.

Top comments (0)