Function: magit-main-branch

magit-main-branch is a byte-compiled function defined in magit-git.el.

Signature

(magit-main-branch)

Documentation

Return the main branch.

If a branch exists whose name matches init.defaultBranch, then that is considered the main branch. If no branch by that name exists, then the branch names in magit-main-branch-names are tried in order. The first branch from that list that actually exists in the current repository is considered its main branch.

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-git.el
(defun magit-main-branch ()
  "Return the main branch.

If a branch exists whose name matches `init.defaultBranch', then
that is considered the main branch.  If no branch by that name
exists, then the branch names in `magit-main-branch-names' are
tried in order.  The first branch from that list that actually
exists in the current repository is considered its main branch."
  (let ((branches (magit-list-local-branch-names)))
    (seq-find (##member % branches)
              (delete-dups
               (delq nil
                     (cons (magit-get "init.defaultBranch")
                           magit-main-branch-names))))))