Function: magit-main-branch
magit-main-branch is a natively compiled function defined in
magit-git.el.
Signature
(magit-main-branch &optional REMOTE)
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.
If optional REMOTE is non-nil, return its default branch. If the symbolic ref "refs/remotes/<REMOTE>/HEAD" exists, return the branch it refers to, else use the same heuristic as when determining the local default.
Source Code
;; Defined in /nix/store/irvbdy0zra0dn8fpd008f32x5ix6qm5v-emacs-packages-deps/share/emacs/site-lisp/elpa/magit-20261005.508/magit-git.el
(defun magit-main-branch (&optional remote)
"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.
If optional REMOTE is non-nil, return its default branch. If the
symbolic ref \"refs/remotes/<REMOTE>/HEAD\" exists, return the branch
it refers to, else use the same heuristic as when determining the
local default."
(or (and remote
(magit-git-string "symbolic-ref" "--short"
(format "refs/remotes/%s/HEAD" remote)))
(let* ((branches (if remote
(magit-list-remote-branch-names remote t)
(magit-list-local-branch-names)))
(branch (seq-find (##member % branches)
(delete-dups
(delq nil
(cons (magit-get "init.defaultBranch")
magit-main-branch-names))))))
(if (and remote branch) (concat remote "/" branch) branch))))