Function: magit-push-current-to-upstream

magit-push-current-to-upstream is an autoloaded, interactive and byte-compiled function defined in magit-push.el.

Signature

(magit-push-current-to-upstream ARG1)

Documentation

Push the current branch to its upstream branch.

With a prefix argument or when the upstream is either not configured or unusable, then let the user first configure the upstream.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-push.el
;;;###autoload(autoload 'magit-push-current-to-upstream "magit-push" nil t)
(transient-define-suffix magit-push-current-to-upstream (args)
  "Push the current branch to its upstream branch.

With a prefix argument or when the upstream is either not
configured or unusable, then let the user first configure
the upstream."
  :if #'magit-get-current-branch
  :description #'magit-push--upstream-description
  (interactive (list (magit-push-arguments)))
  (let* ((branch (or (magit-get-current-branch)
                     (user-error "No branch is checked out")))
         (remote (magit-get "branch" branch "remote"))
         (merge  (magit-get "branch" branch "merge")))
    (when (or current-prefix-arg
              (not (or (magit-get-upstream-branch branch)
                       (magit--unnamed-upstream-p remote merge)
                       (magit--valid-upstream-p remote merge))))
      (let* ((branches (cl-union (mapcar (##concat % "/" branch)
                                         (magit-list-remotes))
                                 (magit-list-remote-branch-names)
                                 :test #'equal))
             (upstream (magit-completing-read
                        (format "Set upstream of %s and push there" branch)
                        branches nil 'any nil 'magit-revision-history
                        (or (car (member (magit-remote-branch-at-point) branches))
                            (car (member "origin/master" branches)))))
             (upstream* (or (magit-get-tracked upstream)
                            (magit-split-branch-name upstream))))
        (setq remote (car upstream*))
        (setq merge  (cdr upstream*))
        (unless (string-prefix-p "refs/" merge)
          ;; User selected a non-existent remote-tracking branch.
          ;; It is very likely, but not certain, that this is the
          ;; correct thing to do.  It is even more likely that it
          ;; is what the user wants to happen.
          (setq merge (concat "refs/heads/" merge)))
        (magit-confirm 'set-and-push
          (list "Really use \"%s\" as upstream and push \"%s\" there"
                upstream branch)))
      (cl-pushnew "--set-upstream" args :test #'equal))
    (run-hooks 'magit-credential-hook)
    (magit-run-git-async "push" "-v" args remote (concat branch ":" merge))))