How to upgrade Git on Mac (OSX)
Recently a vulnerability in Git was discovered that could lead to arbitrary code execution when a developer utilizes a malicious repository. The good news is that this issue has been patched and the fix is available in version 2.17.1.
Now let’s upgrade!
Overview
In this guide we are going to walk through how to upgrade Git via Homebrew. First we will install Homebrew and then install Git. Given that you may have Git already installed (e.g. via XCode), this guide will also walk you through how to change your path to use the official (non-Apple) distribution.
A few details before we get started:
If you are unfamiliar with Homebrew, it is a package manager for Mac that allows you to easily install and utilize a myriad a programs (i.e. formulae).
- For this guide, I am assuming you are running MacOS 10.11 or higher
- Additionally, check out the full Homebrew system requirements here before diving in
Step by Step Guide
Install Homebrew
if Homebrew is already installed, you can skip to the Git section
For installation details, including system requirements check out the documentation here
Update Homebrew to ensure you are on the latest version
Run brew doctor to ensure everything is good to go
If all is well, the output should say Your system is ready to brew.
Now let’s get to Git.
Check your current version of git
If the version of git says something like git version 2.15.1 (Apple Git-101)
then you are running the Apple version of Git, not the official distribution.
No worries, Homebrew has got us covered.
Install git via Homebrew
Change your local path to the Homebrew version
Check the git version
You should now see the current version of git, such as git version 2.17.1
.
To upgrade in the future, simply run
Conclusion
We are all set! Homebrew is installed, Git is installed, and we have changed our path to point to the current version. For further details on Homebrew and some additional resources, check out the links below.
Additional Resources
- Homebrew
- Homebrew Documentation
- How to use the Homebrew installed Git
- Updating paths for Git on StackOverflow
- Step-by-Step on How to Update Git on Mac