Function: magit-branch-reset
magit-branch-reset is an autoloaded, interactive and byte-compiled
function defined in magit-branch.el.
Signature
(magit-branch-reset BRANCH TO &optional SET-UPSTREAM)
Documentation
Reset a branch to the tip of another branch or any other commit.
When the branch being reset is the current branch, then do a hard reset. If there are any uncommitted changes, then the user has to confirm the reset because those changes would be lost.
This is useful when you have started work on a feature branch but realize it's all crap and want to start over.
When resetting to another branch and a prefix argument is used, then also set the target branch as the upstream of the branch that is being reset.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-branch.el
;;;###autoload
(defun magit-branch-reset (branch to &optional set-upstream)
"Reset a branch to the tip of another branch or any other commit.
When the branch being reset is the current branch, then do a
hard reset. If there are any uncommitted changes, then the user
has to confirm the reset because those changes would be lost.
This is useful when you have started work on a feature branch but
realize it's all crap and want to start over.
When resetting to another branch and a prefix argument is used,
then also set the target branch as the upstream of the branch
that is being reset."
(interactive
(let ((branch (magit-read-local-branch "Reset branch"
(magit-local-branch-at-point))))
(list branch
(magit-read-branch-or-commit (format "Reset %s to" branch)
(magit-get-upstream-branch branch)
branch)
current-prefix-arg)))
(let ((magit-inhibit-refresh t))
(if (equal branch (magit-get-current-branch))
(if (and (magit-anything-modified-p)
(not (yes-or-no-p
"Uncommitted changes will be lost. Proceed? ")))
(user-error "Abort")
(magit-reset-hard to))
(magit-call-git "update-ref"
"-m" (format "reset: moving to %s" to)
(magit-ref-fullname branch)
to))
(when (and set-upstream (magit-branch-p to))
(magit-set-upstream-branch branch to)
(magit-branch-maybe-adjust-upstream branch to)))
(magit-refresh))