Sub topic 6
Checking that Git is installed
This chapter assumes you can open a terminal and run commands, and that you have already run an install command for your platform. Here you confirm that the install worked and learn to diagnose it when it didn't.
What a successful check looks like
Open a new terminal window and run:
git --versionA working install prints one line:
git version 2.45.2The number will differ on your machine. Two things matter: the command ran, and the version is recent enough for the features you need. Git follows a major.minor.patch scheme, and most tutorials work with any 2.x release. Newer settings, such as init.defaultBranch (added in 2.28), need a recent release. If your version is older than 2.28, update before continuing.
On macOS you may see a suffix such as (Apple Git-154). That means you are running the Git build that ships with Apple's developer tools, not the Homebrew one. Both work for this tutorial.
What the command actually does
When you type git, your shell does not know where Git lives. It searches each folder listed in the PATH environment variable, in order, and runs the first match. A successful git --version therefore proves two things: Git is installed, and its folder is on your PATH.
Finding which Git you are running
Machines often end up with more than one Git, for example Apple's build plus a Homebrew build. To see which one your shell picks first, ask for its location.
On macOS and Linux:
which gitOn Windows PowerShell:
Get-Command gitTypical results:
| Platform | Typical location | Source |
|---|---|---|
| macOS, Apple silicon | `/opt/homebrew/bin/git` | Homebrew |
| macOS, Intel | `/usr/local/bin/git` | Homebrew |
| macOS | `/usr/bin/git` | Apple developer tools |
| Debian or Ubuntu | `/usr/bin/git` | apt |
| Fedora | `/usr/bin/git` | dnf |
| Windows | `C:\Program Files\Git\cmd\git.exe` | Git for Windows installer or winget |
On Linux and macOS, which -a git lists every match on your PATH, in search order. The first one wins. If the first entry is not the one you intended, the order of folders in PATH is the cause.
Common errors and fixes
Command not found
Typical messages are git: command not found (bash, zsh) or 'git' is not recognized as an internal or external command (Windows). Work through these causes in order:
- The terminal was open before the install. Close it and open a new one.
- The install failed or was never run. Re-run the install command from the previous chapter and read its output for errors.
- Git is installed but its folder is not on
PATH. On Windows, confirm thatC:\Program Files\Git\cmdappears in your PATH settings. On macOS or Linux, runecho $PATHand compare it with the location from your package manager.
macOS opens an installer window
On a Mac with no Git installed, the first git command can trigger a prompt to install the Command Line Tools. That is Apple's shim at /usr/bin/git asking for the real binary. You can accept it, or install Git with Homebrew and make sure /opt/homebrew/bin comes before /usr/bin in PATH.
Version is too old
Distribution packages can lag behind. Older long-term-support Linux releases may ship a Git that predates 2.28. Check with git --version, then either upgrade through your package manager or add a newer source. The Git project documents a PPA for Ubuntu.
A fuller sanity check
git --version only proves the program starts. To confirm it can also read its own configuration and run a subcommand, run these two commands:
git --version
git config --list --show-originOn a fresh install, the second command may print little or nothing from your own files, or only system-level defaults. That is normal, because you have not set your identity yet. The next chapters cover configuration. What matters now is that the command runs without an error.
If you want a single check suitable for a script, for example in a setup guide for a team, use the exit status:
if git --version > /dev/null 2>&1; then
echo "Git is installed"
else
echo "Git is missing or not on PATH"
fiCommands return exit status 0 on success, and a nonzero status when the shell cannot find or run the program. The if statement branches on that status, and the redirects hide the normal output.
Exercise
You installed Git with Homebrew on a Mac, but git --version prints git version 2.39.5 (Apple Git-154). Which command shows the competing installations in search order, and what does the output order tell you?
Show answer
Run which -a git. It lists every git found on PATH in search order. The first entry is the one your shell runs. If /usr/bin/git appears before /opt/homebrew/bin/git (or /usr/local/bin/git on Intel), the Apple build wins. To switch, put the Homebrew folder earlier in PATH.
Exercise
You run git --version right after installing and get "command not found", although the installer reported success. What is the first thing to try, and why?
Show answer
Close the terminal and open a new one. A running terminal keeps the PATH it started with, so it cannot see a folder added by the installer. If the error persists in a new terminal, check that Git's folder is on PATH.