Is there a way to set the upstream of a branch automatically in magit?

I know I can select it interactively but for feature branches I set it to master 99% of the times so I was wondering if it can be done at branch creation automatically.

Thank you!

2 Answers 2


Magit's branch creation commands use git branch new-branch start-point, which in some cases automatically sets start-point as the upstream. Unfortunately it does not do so in all cases in which it should do so IMO.

The relevant documentation is this:

           Tells git branch, git switch and git checkout to set up new
           branches so that git-pull(1) will appropriately merge from the
           starting point branch. Note that even if this option is not set,
           this behavior can be chosen per-branch using the --track and
           --no-track options. The valid settings are: false — no automatic
           setup is done; true — automatic setup is done when the starting
           point is a remote-tracking branch; always —  automatic setup is
           done when the starting point is either a local branch or
           remote-tracking branch. This option defaults to true.

So you want to set that variable to always.

Additionally you might want to read about the magit-branch-adjust-remote-upstream-alist option.

These things are described in more details in the Branch Commands and Branch Git Variables sections of the Magit manual. I recommend you also read the surrounding sections.

  • thank you very informative answer Jan 11, 2020 at 0:05
  • 1
    Ok I will make your anwser the accepted one but for the records I needed this: (setq magit-branch-adjust-remote-upstream-alist '(("origin/master"))). Small caveat, this works only when branching from a remote branch (e.g. from origin/master but not from master. Jan 11, 2020 at 0:21

Starting from Git version 2.35, you can set now set branch.autoSetupMerge = inherit. It will inherit the tracking configuration from the starting point and set is on your new branch.

That is, if you have a main branch that is tracking upstream origin/main and you create a new branch starting at main, your new branch will be set to track origin/main instead of main as with branch.autoSetupMerge = always.

I got this information from this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.