Function: magit-init

magit-init is an autoloaded, interactive and byte-compiled function defined in magit-status.el.

Signature

(magit-init DIRECTORY)

Documentation

Initialize a Git repository, then show its status.

If the directory is below an existing repository, then the user has to confirm that a new one should be created inside. If the directory is the root of the existing repository, then the user has to confirm that it should be reinitialized.

Non-interactively DIRECTORY is (re-)initialized unconditionally.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-status.el
;;; Commands

;;;###autoload
(defun magit-init (directory)
  "Initialize a Git repository, then show its status.

If the directory is below an existing repository, then the user
has to confirm that a new one should be created inside.  If the
directory is the root of the existing repository, then the user
has to confirm that it should be reinitialized.

Non-interactively DIRECTORY is (re-)initialized unconditionally."
  (interactive
    (let ((directory (file-name-as-directory
                      (expand-file-name
                       (read-directory-name "Create repository in: ")))))
      (when-let ((toplevel (magit-toplevel directory)))
        (setq toplevel (expand-file-name toplevel))
        (unless (y-or-n-p (if (file-equal-p toplevel directory)
                              (format "Reinitialize existing repository %s? "
                                      directory)
                            (format "%s is a repository.  Create another in %s? "
                                    toplevel directory)))
          (user-error "Abort")))
      (list directory)))
  ;; `git init' does not understand the meaning of "~"!
  (magit-call-git "init" (magit-convert-filename-for-git
                          (expand-file-name directory)))
  (magit-status-setup-buffer directory))