Installing and configuring Git
Getting a working Git install plus the minimum global configuration — identity, line endings, and auth — so your first commit is correct and reproducible.
Why it matters
A misconfigured install produces commits attributed to root@hostname, mangled line endings that show every file as changed, and credential prompts on every push. Five minutes of one-time global setup prevents weeks of noisy diffs and “who is this author?” confusion across every repo on the machine. Identity in particular (user.email) is baked immutably into each commit.
How it works
Install per platform, then verify:
| OS | Install | Verify |
|---|---|---|
| macOS | brew install git (or Xcode CLT) | git --version |
| Debian/Ubuntu | apt install git | git --version |
| Windows | Git for Windows installer | bundles Git Bash |
Modern Git ships in 2.4x+; check with git --version. Then set the essential globals (stored in ~/.gitconfig):
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
git config --global init.defaultBranch main # not "master"
git config --global core.autocrlf input # mac/linux; "true" on Windows
git config --global pull.rebase false # be explicit, avoid warnings
Config is layered: system (/etc/gitconfig) < global (~/.gitconfig, --global) < local (.git/config, default in a repo). Nearer scopes win. See git-config-user-name-user-email-core-editor for the per-key detail and git config --list --show-origin to see where each value comes from.
Example
Fresh laptop, end to end:
brew install git && git --version → git version 2.45.2
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
git config --global core.autocrlf input
git config --get user.email → ada@example.com
Per-repo override for a work email: inside the repo, git config user.email "ada@work.com" writes to local scope only.
Pitfalls
- Forgetting identity before the first commit — it lands as
unknown/root; fix retroactively with —amend or rebase. - Wrong
core.autocrlf—trueon macOS/Linux corrupts files; useinputthere,trueon Windows. - Editing
~/.gitconfigby hand and breaking syntax — prefergit configcommands; a malformed file makes every command error. - Leaving
init.defaultBranchas master — mismatches GitHub’smainand breakspush -u origin main.