Homebrew is the undisputed king of macOS package management, but sometimes you want the absolute bleeding edge of a tool like Git. Here’s how to ditch the system-installed (and often ancient) Git for the latest stable release via Homebrew.
First, let’s make sure Homebrew itself is up-to-date. This is crucial because older Homebrew versions might not even have the latest Git.
brew update
This command fetches the newest list of available packages and their versions from Homebrew’s remote repositories. It’s a quick sync that ensures you’re working with the most current information.
Now, let’s install Git. If you already have a version of Git installed by Homebrew, this command will upgrade it. If you only have the macOS system Git, it will install Homebrew’s version and, importantly, tell you how to use it.
brew install git
Homebrew will download the Git source code, compile it (if necessary), and install it into its managed directory, typically /usr/local/Cellar/git/ or /opt/homebrew/Cellar/git/ on Apple Silicon Macs.
The most critical step after installation is ensuring your system uses the Homebrew-installed Git, not the one that came with macOS. The system Git is usually located at /usr/bin/git. Homebrew installs its version at a path like /usr/local/bin/git or /opt/homebrew/bin/git. Your shell’s PATH environment variable dictates which executable is found first.
Homebrew’s brew install git command usually prints instructions on how to adjust your PATH. You’ll typically need to add Homebrew’s bin directory to the beginning of your PATH. Here’s how to do it for your shell’s configuration file.
If you use bash (common on older macOS versions or if you’ve explicitly chosen it), edit ~/.bash_profile or ~/.bashrc:
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
Or for Apple Silicon:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.bash_profile
If you use zsh (the default on modern macOS), edit ~/.zshrc:
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc
Or for Apple Silicon:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
After saving the file, you need to either close and reopen your terminal or source the file for the changes to take effect immediately:
source ~/.bash_profile # or source ~/.zshrc
To verify that you’re now using the Homebrew version, run:
which git
This should output /usr/local/bin/git or /opt/homebrew/bin/git. If it still shows /usr/bin/git, your PATH is not set up correctly, or you haven’t reloaded your shell’s configuration.
You can also check the version:
git --version
This should now display the latest version number you just installed.
You’ve successfully upgraded Git. The next hurdle is often managing multiple Git identities or understanding how to leverage newer Git features that might not be present in older versions.