Function: magit--branch-spinoff
magit--branch-spinoff is a byte-compiled function defined in
magit-branch.el.
Signature
(magit--branch-spinoff BRANCH FROM CHECKOUT)
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-branch.el
(defun magit--branch-spinoff (branch from checkout)
(when (magit-branch-p branch)
(user-error "Cannot spin off %s. It already exists" branch))
(when (and (not checkout)
(magit-anything-modified-p))
(message "Staying on HEAD due to uncommitted changes")
(setq checkout t))
(cond-let
([current (magit-get-current-branch)]
(let ((tracked (magit-get-upstream-branch current))
base)
(when from
(unless (magit-rev-ancestor-p from current)
(user-error "Cannot spin off %s. %s is not reachable from %s"
branch from current))
(when (and tracked
(magit-rev-ancestor-p from tracked))
(user-error "Cannot spin off %s. %s is ancestor of upstream %s"
branch from tracked)))
(let ((magit-process-raise-error t))
(if checkout
(magit-call-git "checkout" "-b" branch current)
(magit-call-git "branch" branch current)))
(when$ (magit-get-indirect-upstream-branch current)
(magit-call-git "branch" "--set-upstream-to" $ branch))
(when (and tracked
(setq base
(if from
(concat from "^")
(magit-git-string "merge-base" current tracked)))
(not (magit-rev-eq base current)))
(if checkout
(magit-call-git "update-ref" "-m"
(format "reset: moving to %s" base)
(concat "refs/heads/" current) base)
(magit-call-git "reset" "--hard" base)))))
(checkout
(magit-call-git "checkout" "-b" branch))
((magit-call-git "branch" branch)))
(magit-refresh))