Search code examples
macosemacsmagit

Can't find git executable


I'm using Emacs 24 on OS X 10.6.8. Doing magit-status says

Searching for program: no such file or directory, git

However, the Emacs shell is able to find git, so this does not seem to be a $PATH issue. What else could it be?


Solution

  • Try checking the value of exec-path variable. This controls the directories which are looked by Emacs for external executables (including git).

    This is a customizable variable, and you can add the path to git to the list of existing directories.

    I have the elisp snippet in my .emacs.d/init.el file for my Emacs install under OSX, which sets both the PATH and exec-path correctly.

    ;;; Set localized PATH for OS X
    (defun my-add-path (path-element)
      "Add the specified PATH-ELEMENT to the Emacs PATH."
      (interactive "DEnter directory to be added to path: ")
      (if (file-directory-p path-element)
         (progn
           (setenv "PATH" (concat (expand-file-name path-element) path-separator (getenv "PATH")))
           (add-to-list 'exec-path (expand-file-name path-element)))))
    
    (if (fboundp 'my-add-path)
       (let ((my-paths (list "/opt/local/bin" "/usr/local/bin" "/usr/local/git/bin")))
          (dolist (path-to-add my-paths (getenv "PATH"))
             (my-add-path path-to-add))))