Install & first-time config
Install Git and set the global user identity that every commit will permanently embed.
What you'll learn
- How to install Git on macOS, Linux, and Windows
- Why Git requires your name and email before you can commit
- The difference between --system, --global, and --local config scopes
Before you start
Install Git
Pick the instructions for your platform. The goal is just to get Git on your PATH — keep this step fast.
macOS
The quickest path is Homebrew:
brew install git
No Homebrew? Run git --version in Terminal. macOS will offer to install the Xcode Command Line Tools automatically, which bundles a perfectly adequate Git.
Debian / Ubuntu Linux
sudo apt update && sudo apt install git
Windows
Download and run the installer from git-scm.com. The defaults are fine. This installs Git Bash and adds Git to your PATH.
Verify the installation
git --version
git version 2.44.0
The exact version number doesn’t matter — any recent 2.x release works for everything in these lessons.
Why Git needs your identity
Every Git commit stores two pieces of metadata that are baked into the commit hash and travel with the repository forever:
- Author name — who wrote the change
- Author email — how to reach them
This is not optional. Git enforces it because commit history is meant to be trustworthy and attributable. When you push to GitHub or share a repo with a team, every commit carries this identity permanently. You cannot edit it after the fact without rewriting history (which breaks other people’s clones).
Because of this, Git refuses to create a commit until these two values are set.
First-time setup
Run these three commands once, right after installing Git. Replace the placeholder values with your own.
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
git config --global init.defaultBranch main
What each line does:
user.name— the human-readable name embedded in every commit you make on this machine.user.email— the email embedded in every commit. GitHub uses this to link commits to your account avatar.init.defaultBranch main— makesgit initcreate a branch namedmaininstead of the legacymaster. Most platforms default tomaintoday; setting this avoids a warning on every new repo.
Optional: set your preferred editor
Git opens a text editor when you run git commit without a -m flag. The default is vi, which surprises many people. Override it:
git config --global core.editor "code --wait"
Replace code --wait with nano, vim, emacs --wait, or whatever you prefer.
Inspect your config
After setting values, verify them:
git config --list
user.name=Ada Lovelace
user.email=ada@example.com
init.defaultbranch=main
core.editor=code --wait
To read a single key:
git config user.email
ada@example.com
Config scopes: system, global, local
Git reads config from three files and merges them at runtime. More specific always wins.
| Scope | Flag | File location | When to use |
|---|---|---|---|
| System | --system | /etc/gitconfig (Linux/macOS) | Admins setting org-wide defaults |
| Global | --global | ~/.gitconfig | Your personal identity on this machine |
| Local | --local | .git/config inside a repo | Work email for one specific repo |
A common real-world pattern: set your personal email globally, then override it with your work email locally inside each work repo:
cd ~/work/company-project
git config --local user.email "ada@company.com"
Now commits in that repo use your work email; commits everywhere else still use your personal email.
What you can skip for now
The git config command has dozens of options (color.ui, pull.rebase, merge.tool, etc.). Ignore them until a workflow problem makes one relevant. The three commands in the “First-time setup” section above are the only ones you need before your first commit.