Installing Git
Before you can run a single Git command, Git itself has to be on your machine. Git is a free, open-source program that runs entirely from the command line (though graphical tools exist on top of it), and installing it takes only a few minutes on any operating system. This lesson walks through installing Git on Windows, macOS, and Linux, verifying the install worked, and doing the small one-time configuration every new Git installation needs before you make your first commit.
Overview / How it works
Git is a standalone program — a command-line executable named git — that your operating system needs to know how to find. When you type a command like git status into a terminal, your shell searches the directories listed in your system’s PATH environment variable for a program called git, and runs it. Installing Git means placing that executable (plus its supporting files) somewhere on disk and making sure it’s on the PATH. Package managers handle this automatically; manual installers do too, as long as you don’t skip the “add to PATH” step.
Once installed, Git needs a small amount of configuration before it will let you commit. Every commit you create is stamped with an author name and email address, baked directly into the commit object Git stores — this is not optional metadata, it’s part of what makes the commit’s SHA-1 hash unique. If you try to commit before setting an identity, Git will refuse (or invent a low-quality default based on your OS username and hostname), so setting user.name and user.email is the very first thing you do after installing.
There are three common ways to get Git onto a machine:
- A package manager —
apt/dnfon Linux,brewon macOS,wingetorchocoon Windows. This is the recommended path: it’s scriptable, keeps Git up to date with a single command later, and is how most professional developers install it. - An official installer — the
.exefrom git-scm.com on Windows, or the macOS.pkgfrom the same site. Good for a one-off GUI install on a machine you don’t want to touch the command line on yet, ironically, to install the command line tool. - Bundled with other tools — Xcode Command Line Tools on macOS, or a Linux distribution that ships Git preinstalled. Worth checking before you install anything, since it may already be there.
What version should you install?
Any Git 2.30 or newer supports everything taught in this course, including git switch and git restore, the newer, more focused replacements for parts of git checkout. Package managers will almost always give you something newer than that already. There’s rarely a reason to pin an old version deliberately — install whatever your package manager offers as “stable” and move on.
Syntax
There’s no single install “command” — it depends on your OS and package manager. The table below covers the common paths. After installing, two commands matter everywhere:
| Command | Purpose |
|---|---|
git --version |
Confirms Git is installed and shows which version |
git config --global <key> <value> |
Sets a configuration value for every repository on this machine |
git config --global --unset <key> |
Removes a previously set global config value |
git config --list --show-origin |
Lists every active config value and which file it came from |
Git configuration is layered: system (applies to every user on the machine), global (applies to every repository for your user, stored in ~/.gitconfig), and local (applies to one repository only, stored in .git/config). A more specific level always overrides a less specific one — local beats global beats system. For your identity, you’ll almost always use --global.
Examples
Example 1 — Installing Git and checking the version
On Ubuntu or Debian-based Linux:
sudo apt update
sudo apt install git
On macOS, with Homebrew installed:
brew install git
On Windows, using the built-in winget package manager (run in PowerShell):
winget install --id Git.Git -e --source winget
Whichever platform you used, close and reopen your terminal, then confirm the install:
git --version
Output:
git version 2.43.0
The exact version number will differ, and that’s fine — anything 2.30 or above is ready for this course. If you instead see something like command not found: git or 'git' is not recognized as an internal or external command, Git either failed to install or isn’t on your PATH; reopening the terminal (or restarting the machine, on Windows) fixes most PATH issues after a fresh install.
Example 2 — Setting your identity
Every commit needs an author name and email baked in, so this is the first configuration step on any new machine:
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
Verify it took effect:
git config --global --list
Output:
user.name=Ada Lovelace
user.email=ada@example.com
Use the same email address here that you’ll use for your GitHub account — GitHub matches commit authorship to profiles by email, and a mismatch is why commits sometimes show up without your avatar or a link to your profile on GitHub’s web UI.
Example 3 — Setting the default branch name and a text editor
Older Git versions default a newly initialized repository’s first branch to master; modern convention is main. Set it once globally so every future repository you create starts on main without you having to rename it:
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
The second line tells Git which text editor to open for things like writing a multi-line commit message or resolving a merge — here, VS Code, using --wait so Git pauses until you close the editor tab. If you’d rather stay in the terminal, use nano or vim instead of code --wait. Now prove the default branch setting works:
git init learning-git
cd learning-git
git branch --show-current
Output:
main
Without setting init.defaultBranch, older Git versions would print master here instead, and you’d need git branch -m main to rename it after the fact.
How it works step by step
- The package manager (or installer) downloads the
gitbinary and supporting files — templates, man pages, credential helpers — and places them in a standard system directory, such as/usr/binon Linux,/usr/local/binor/opt/homebrew/binon macOS, orProgram Files\Git\binon Windows. - The installer adds that directory to your
PATH, so your shell can locate thegitexecutable by name from any working directory. - Running
git --versionis itself a full invocation of the program — your shell resolvesgitviaPATH, executes it with the single argument--version, and Git prints its version string and exits. This is the simplest possible proof that installation succeeded. - Running
git config --global <key> <value>does not talk to any repository. It opens (creating if necessary) your global config file at~/.gitconfig(or%USERPROFILE%\.gitconfigon Windows) and writes an INI-style key/value pair into it. - Every later Git command in every repository on this machine reads that global config file, layered underneath any local
.git/configin the current repository, to decide who you are and how you like your editor and default branch configured.
Common Mistakes
Mistake 1: Committing before setting an identity
On a brand-new install, running git commit without configuring user.name/user.email first either fails outright or silently uses a guessed identity built from your OS account and hostname (e.g. ada@Ada-Laptop.(none)):
git commit -m "fix: correct typo in README"
Why it’s wrong: that guessed identity is not tied to your GitHub account, so commits made this way never link back to your profile. The fix: run the two git config --global user.name / user.email commands from Example 2 immediately after installing, before you touch any real repository.
Mistake 2: Installing Git but not restarting the terminal
Especially on Windows, running git --version in the same terminal window that was open during installation often still fails with 'git' is not recognized..., even though the install succeeded, because that terminal’s PATH was loaded before the installer updated it. The fix: close the terminal completely and open a new one (or restart the machine) so it picks up the updated PATH.
Mistake 3: Installing an ancient bundled version and never updating it
Some Linux distributions and older macOS versions ship a Git that’s several years old, which may be missing git switch/git restore or newer safety defaults. Running git --version and seeing something like git version 2.17.1 is a sign to update via your package manager (sudo apt upgrade git, brew upgrade git) rather than working around missing commands indefinitely.
Best Practices
- Install Git through your platform’s package manager (
apt,brew,winget) rather than a manually downloaded installer where possible — it makes future updates a one-line command. - Set
user.nameanduser.emailglobally immediately after installing, using the same email as your GitHub account. - Set
init.defaultBranch mainglobally so you never have to think about renamingmastertomainon new repositories. - Pick one text editor for
core.editorand stick with it — getting dropped into an unfamiliar terminal editor likevimmid-commit, with no idea how to save and quit, is a common source of early Git frustration. - Run
git --versionright after installing, every time, as a cheap sanity check before you do anything else. - Keep Git reasonably up to date; security fixes and usability improvements land in most releases, and it costs one command via your package manager.
Practice Exercises
- Install Git using the method appropriate for your operating system, then run
git --versionand confirm you see 2.30 or newer. - Set your global
user.nameanduser.emailto your own name and the email address you plan to use for GitHub, then rungit config --global --listto confirm both values are set correctly. - Set
init.defaultBranchtomain, then rungit init sandbox-repofollowed bygit branch --show-currentinside that new folder — confirm the output readsmain, notmaster.
Summary
- Git is a standalone command-line program; installing it means putting the
gitexecutable on disk and on your system’sPATH. - Use your platform’s package manager —
apt/dnfon Linux,brewon macOS,winget/chocoon Windows — for the easiest install and future updates. - Any Git 2.30+ supports the modern commands taught in this course, including
git switchandgit restore. - Verify an install with
git --version; if the command isn’t found, reopen your terminal so it picks up the updatedPATH. - Immediately after installing, set
user.name,user.email, andinit.defaultBranch mainwithgit config --global— commits are stamped with your identity and cannot be created without it. - Config is layered: system, then global (
~/.gitconfig), then local (.git/config) — more specific always wins.
