Installing and Configuring Git
Before you can use Git, you need it installed and configured with your identity. Configuration is a one-time step per machine — once done, every commit you make on that computer will carry your name and email automatically.
Checking if Git is already installed
Section titled “Checking if Git is already installed”Open a terminal (Terminal on macOS, Git Bash or PowerShell on Windows) and run:
git --versionIf Git is installed, you will see output like:
git version 2.44.0The exact version number does not matter as long as it is 2.x or higher. If the command is not found, continue with the installation steps below.
Installing Git on macOS
Section titled “Installing Git on macOS”Option 1: Xcode Command Line Tools (recommended — no extra software needed)
Run this in your terminal:
xcode-select --installA dialog will appear asking you to install the Command Line Tools. Click Install and wait for it to complete. Git is included.
Option 2: Homebrew
If you already have Homebrew installed:
brew install gitAfter either option, run git --version to confirm the installation.
Installing Git on Windows
Section titled “Installing Git on Windows”Download and run the installer from git-scm.com. The default options work for most setups. During installation:
- Accept the default editor (you can change this later)
- Choose “Git from the command line and also from 3rd-party software” when asked about PATH
- Accept the default line ending settings
The installer includes Git Bash, a terminal that provides a Unix-style shell on Windows. You can use Git Bash or Windows Terminal for all commands in this course.
After installation, open Git Bash and run git --version to confirm.
Configuring your identity
Section titled “Configuring your identity”Every Git commit records who made it. Before you create your first commit, tell Git your name and email:
git config --global user.name "Your Name"git config --global user.email "you@example.com"Use the same email address you will use for your GitHub account. This links your local commits to your GitHub profile.
The --global flag applies this configuration to every repository on your machine. You can override it per-repository by running the same commands without --global inside that repository’s folder.
Setting the default branch name
Section titled “Setting the default branch name”Modern Git and GitHub both use main as the default branch name. Older Git installations default to master. Set it to main now to avoid a mismatch later:
git config --global init.defaultBranch mainVerifying your configuration
Section titled “Verifying your configuration”Review what you have set:
git config --global --listYou should see your name, email, and default branch name in the output:
user.name=Your Nameuser.email=you@example.cominit.defaultBranch=mainOptional: setting your editor
Section titled “Optional: setting your editor”Git occasionally opens a text editor for things like commit messages you did not provide with -m. The default is vi, which is unfamiliar to most beginners. To use VS Code instead:
git config --global core.editor "code --wait"This requires that VS Code is installed and the code command is available in your PATH. If you are not sure, skip this for now — you will use the -m flag for commit messages throughout this course and will not need the editor to open.
Exercise
Section titled “Exercise”-
Open your terminal and run
git --version. If Git is not installed, complete the installation for your operating system. -
Run the three configuration commands with your name, email, and default branch:
git config --global user.name "Your Name"git config --global user.email "you@example.com"git config --global init.defaultBranch main- Run
git config --global --listand verify that all three values appear in the output.
- Run
git --versionto check whether Git is already installed. - macOS: install via Xcode Command Line Tools (
xcode-select --install) or Homebrew. - Windows: install via the Git for Windows installer at git-scm.com.
git config --global user.nameandgit config --global user.emailset your identity for all commits on this machine.git config --global init.defaultBranch mainsets the default branch name to match GitHub’s convention.git config --global --listlets you review everything you have configured.
Next you will create your first Git repository — a folder tracked by Git — and see what happens inside it.