I am currently trying to configure a custom development environment on my MacBook and I need to locate the exact directory where Git is installed. I’ve noticed that macOS comes with a version of Git pre-installed via Xcode, but I also have a version I installed via Homebrew. How can I distinguish between these paths in the terminal, and which directory should I point my IDE to if I want to ensure I am using the most up-to-date version for my software development projects?
3 answers
The quickest way to find where your active Git binary is located is by opening the Terminal and typing which git. If you are using the default Apple version, it will likely return /usr/bin/git. However, if you installed it via Homebrew, the path will typically be /usr/local/bin/git (on Intel Macs) or /opt/homebrew/bin/git (on Apple Silicon M1/M2/M3 Macs). To see all versions installed on your system, use the command whereis git or type -a git. For modern Software Development, I highly recommend pointing your IDE to the Homebrew path, as it allows you to update Git independently of major macOS system updates, ensuring you always have access to the latest security patches and features.
That is a helpful breakdown! But what if the terminal returns a path that looks like a symlink? Are there specific flags I should use with the ls -l command to trace that link back to the actual source folder in the Cellar directory if I’m using Homebrew?
You can also run git --exec-path in your terminal. This specifically tells you where the Git sub-programs are stored, which is usually right inside the main installation folder.
I agree with Jennifer. The --exec-path command is a hidden gem for debugging. As Kimberly mentioned in her post, knowing exactly which version you are running is crucial when you start working with advanced features like git-lfs or custom hooks that might be version-dependent.
Steven, you can use readlink -f $(which git) to resolve the full symbolic link path immediately. This is particularly useful when you need to find the actual executable for setting up environment variables like GIT_EXEC_PATH. On macOS, many binaries in /usr/local/bin are just pointers, so following the trail to the actual installation folder ensures that your configuration doesn't break if you move or update your package manager settings later on.