2

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!

3

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:

       branch.autoSetupMerge
           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 – Andrea Richiardi Jan 11 at 0:05
  • 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. – Andrea Richiardi Jan 11 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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