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-20261018.804/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 ((upstream (magit-completing-read
                       (format "Set upstream of %s and push there" branch)
                       (seq-union (mapcar (##concat % "/" branch)
                                          (magit-list-remotes))
                                  (magit-list-remote-branch-names))
                       nil 'any nil 'magit-revision-history
                       (or (magit-remote-branch-at-point)
                           (and$ (magit-primary-remote)
                                 (magit-main-branch $))))))
        (pcase-setq `(,remote . ,merge)
                    (or (magit-get-tracked upstream)
                        (magit-split-branch-name 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))))