Function: magit-checkout

magit-checkout is an autoloaded, interactive and byte-compiled function defined in magit-branch.el.

Signature

(magit-checkout COMMIT &optional ARGS)

Documentation

Checkout COMMIT, updating the index and the working tree.

If COMMIT is a local branch, then that becomes the current branch. If it is something else, then HEAD becomes detached. Checkout fails if the working tree or the staging area contain changes.

(git checkout COMMIT).

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-branch.el
;;;###autoload
(defun magit-checkout (commit &optional args)
  "Checkout COMMIT, updating the index and the working tree.
If COMMIT is a local branch, then that becomes the current
branch.  If it is something else, then `HEAD' becomes detached.
Checkout fails if the working tree or the staging area contain
changes.
\n(git checkout COMMIT)."
  (declare (interactive-only magit--checkout))
  (interactive (list (magit-read-other-branch-or-commit "Checkout")
                     (magit-branch-arguments)))
  (when (string-match "\\`heads/\\(.+\\)" commit)
    (setq commit (match-str 1 commit)))
  (magit-run-git-async "checkout" args commit))