I last tested these instructions on macOS Ventura 13.3.1.
In this step-by-step guide, you'll learn how to install Git with Homebrew in six easy steps.
Installing the Command Line Developer Tools is the first thing you must do to start setting up your Mac for software development. When you do that, you get Git as part of the package.
The problem is that it takes work to keep that Git installation updated. That's why we install a new version of Git with Homebrew and one that's easy to update.
But first things first, if you still need to install the Command Line Developer Tools or need clarification, head to my guide on How to install Command Line Developer Tools on macOS, then get back here to proceed.
Homebrew is a popular package manager for macOS that simplifies the installation and management of software packages and libraries. It allows users to easily install, update, and uninstall a wide range of command-line tools and applications from a vast repository of packages.
If you still need to install Homebrew or need clarification, head to my guide on How to install and use Homebrew on macOS, then get back here to proceed.
Do not type the
$ sign you see in the command examples in this article. That's just an indicator that you should run the command that follows it in your command line tool.
Let's check which version of Git you have installed by running the following command:
You should see something like the following:
git version 2.39.2 (Apple Git-143)
Also, take a look at where this Git version is installed by running this:
You should see an output like this:
Before proceeding, let's update Homebrew itself to have everything fresh:
You might already have Git installed with Homebrew and can't remember it, or maybe you're just curious to learn how to check that.
To see all packages you have installed with Homebrew, run the following command:
If you can't see Git listed, you don't have it installed!
An easier way to check for a specific package when you have too many installed with Homebrew is by running the
list command with the name of the package after it, like the following:
brew list git
If you have Git installed, you'll get an output with several lines starting with something like this:
/opt/homebrew/Cellar/git/... /opt/homebrew/Cellar/git/... /opt/homebrew/Cellar/git/...
In that case, you can head to the How to update Git section at the end of this post.
Otherwise, you should get this:
Error: No such keg: /opt/homebrew/Cellar/git
In that case, let's move on.
It's pretty easy to install Git using Homebrew, but before proceeding, let's find out the latest version of Git available on Homebrew. To do that, run the following command:
brew info git
The first line of the output should be something like the following:
==> git: stable 2.40.1 (bottled), HEAD
With that information, you can compare this version with the one you already have installed (we checked that in Step 1). So after the installation, you can ensure the latest version, the Homebrew-installed version, takes precedence over the one installed with the Command Line Developer Tools.
Now let's finally install the latest Git version using Homebrew. To do that, run the following command:
brew install git
You should see a bunch of output and something like the following close to the bottom:
==> Summary 🍺 /opt/homebrew/Cellar/git/2.40.1: 1,635 files, 48.9MB
That means Homebrew installed Git successfully!
Now, if you open a new Terminal window or tab and run
$ git --version, you should see the just installed version.
To make it work on your current Zsh instance, you must run the following command to reload it, making the installation changes take effect:
Now if you run
$ git --version, you should see the latest one!
And if you run
$ which git, you should see this:
Instead of this (as before):
Congrats, you now have Git installed with Homebrew and can easily update it! 🎉
Let's see how next.
The whole point of installing another version of Git with Homebrew is that you can easily update it by running the following command:
brew upgrade git
And that's it. 😎
The first thing you should do when you install Git is to set your name and email address. That's important because every Git commit uses this information to identify its author.
To do that, run the following commands:
git config --global user.name "Your Name"
git config --global user.email firstname.lastname@example.org
Don't forget to replace
Your Name and
--global argument makes it globally available for Git, so it's used in any Git repository you work with. If you want to override that information for a specific repo, go to that repo's root directory and run that command without the
You can run the following command to double-check your info:
git config --list
You should see a bunch of information, including
And that's it for this guide. I hope you enjoyed it!
Thank you for reading, and let me know if you have any issues or suggestions in the comments below.
How to set up your Mac for software development
How to install and use Antigen and Oh My Zsh on macOS
How to generate and use SSH keys on macOS
How to sign Git commits with SSH keys on macOS
How to install and run Node.js with nvm on macOS
Introduction to Git
Git Basic Commands Explained
Git Branching and Merging
Git Remote and Tracking Branches
How to install Git with Homebrew on macOS by Flavio Silva is licensed under a Creative Commons Attribution 4.0 International License.