If you’re using Magit on macOS, here’s a tip that will either improve your life considerably or not affect you at all. The tip is from Greg Newman who says that it reduced his commit time from about 4 seconds to less than a second.
The secret? It turns out to be simply specifying a pointer to the git executable like this:
(use-package magit :bind ("C-x g" . magit-status) :custom (magit-git-executable "/opt/homebrew/bin/git"))
Of course, after the excitement dies down, you start thinking, “Wait! What? That can’t be right.” Well, what can’t be right is that it’s taking 3 seconds to find the git executable by searching the PATH variable. What is happening then?
It turns out that Apple provides a copy of git that it puts in /usr/bin/ but if you’re using Homebrew and loaded git with it, the executable lives in another place. In Newman’s case, that place is /opt/homebrew/bin/. In my case, it’s in another place but the same thing happens: there are two versions of git in your file system and unless you’ve performed surgery on your PATH variable, Emacs will probably find the older version provided by Apple.
What’s really going on here, it seems, is that without some further action on your part, Emacs—or more precisely, Magit— may be finding the older, presumably slower, version of git. You might wonder why someone would load git from Homebrew. As I recall, the version of git provided by Apple wasn’t quite working correctly and, in any event, you might want the latest version with all its improvements and bug fixes.
Regardless, if Magit seems slow you should:
- Make sure you have the latest version of git loaded from Homebrew or elsewhere
- Ensure that Magit finds that git either by adjusting your
PATHvariable or setting an explicit path as Newman does.