Function: magit-init
magit-init is an interactive and natively 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
magit-mode-map I
Source Code
;; Defined in /nix/store/irvbdy0zra0dn8fpd008f32x5ix6qm5v-emacs-packages-deps/share/emacs/site-lisp/elpa/magit-20261005.508/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))