Function: magit-get-upstream-branch

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

Signature

(magit-get-upstream-branch &optional BRANCH)

Documentation

Return the name of the upstream branch of BRANCH.

It BRANCH is nil, then return the upstream of the current branch if any, nil otherwise. If the upstream is not configured, the configured remote is an url, or the named branch does not exist, then return nil. I.e., return the name of an existing local or remote-tracking branch. The returned string is colorized according to the branch type.

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-git.el
(defun magit-get-upstream-branch (&optional branch)
  "Return the name of the upstream branch of BRANCH.
It BRANCH is nil, then return the upstream of the current branch
if any, nil otherwise.  If the upstream is not configured, the
configured remote is an url, or the named branch does not exist,
then return nil.  I.e., return the name of an existing local or
remote-tracking branch.  The returned string is colorized
according to the branch type."
  (magit--with-refresh-cache
      (list default-directory 'magit-get-upstream-branch branch)
    (and-let* ((branch (or branch (magit-get-current-branch)))
               (upstream (magit-ref-abbrev (concat branch "@{upstream}"))))
      (magit--propertize-face
       upstream (if (equal (magit-get "branch" branch "remote") ".")
                    'magit-branch-local
                  'magit-branch-remote)))))