Before you can track a single line of code, you need Git installed and properly configured with your identity. Git embeds your name and email into every commit you create — this attribution is permanent and visible to everyone who clones the repository.
Installing Git
macOS
# Option 1: Homebrew (recommended — gets you the latest version)
brew install git
# Option 2: Apple Command Line Developer Tools (pre-installed or auto-prompted)
# Just run git in Terminal — if not installed, macOS prompts you automatically
git --version
# Verify after installation
git --version
# git version 2.45.0
Ubuntu / Debian Linux
sudo apt update && sudo apt install -y git
git --version
# git version 2.43.0
RHEL / CentOS / Amazon Linux
sudo yum install -y git # CentOS 7 / Amazon Linux 2
# or
sudo dnf install -y git # CentOS 8+ / RHEL 8+
Windows
# Option 1: winget (Windows Package Manager — built into Windows 10/11)
winget install --id Git.Git -e --source winget
# Option 2: Official installer from https://git-scm.com
# Recommended settings during install:
# - Default editor: VS Code (not Vim)
# - Adjust PATH: Git from command line and 3rd-party software
# - Line endings: Checkout Windows-style, commit Unix-style
Essential First-Time Configuration
Git uses a layered configuration system:
/etc/gitconfig → System-wide (all users on this machine)
~/.gitconfig → Global (your user account — applies to ALL repos)
<repo>/.git/config → Local (only this specific repository)
More specific settings override less specific ones (local > global > system)
1. Your Identity (Required)
git config --global user.name "Jane Smith"
git config --global user.email "jane@yourcompany.com"
These values appear in every commit you create. Use the same email as your GitHub account so commits link to your GitHub profile.
2. Default Branch Name
# Modern default: main (not the legacy "master")
git config --global init.defaultBranch main
3. Line Ending Handling
Without this, files edited on Windows (CRLF) and Mac/Linux (LF) will show false "changes" in git diff:
# macOS / Linux
git config --global core.autocrlf input
# → Store files with LF, convert CRLF→LF on commit (no conversion on checkout)
# Windows
git config --global core.autocrlf true
# → Store files with LF, convert LF→CRLF on checkout, CRLF→LF on commit
4. Default Editor
When git needs you to write a message (merge commit, rebase), it opens an editor:
# VS Code (most popular choice)
git config --global core.editor "code --wait"
# Nano (simple, beginner-friendly)
git config --global core.editor nano
# Vim (if you know it)
git config --global core.editor vim
5. Useful Aliases
# Compact, visual commit graph (type "git lg" instead of the full command)
git config --global alias.lg "log --oneline --graph --decorate --all"
# Short status
git config --global alias.st "status -sb"
# Undo last commit but keep changes staged
git config --global alias.undo "reset HEAD~1 --mixed"
# Safe force push (only pushes if remote hasn't changed)
git config --global alias.pushf "push --force-with-lease"
6. Rebase on Pull (Recommended)
# When you pull, rebase your local commits on top of remote instead of creating merge commits
git config --global pull.rebase true
This keeps your history linear and clean — no "Merge branch 'main' of github.com/..." noise commits.
Verify Your Configuration
# Show all active configuration and where each setting comes from
git config --list --show-origin
# Output:
# file:/Users/jane/.gitconfig user.name=Jane Smith
# file:/Users/jane/.gitconfig user.email=jane@yourcompany.com
# file:/Users/jane/.gitconfig core.autocrlf=input
# file:/Users/jane/.gitconfig init.defaultbranch=main
# file:/Users/jane/.gitconfig alias.lg=log --oneline --graph --decorate --all
# Check a specific setting
git config user.name
# Jane Smith
# View the raw global config file
cat ~/.gitconfig
SSH Authentication: The Right Way to Use GitHub
GitHub removed password authentication in 2021. The two options are:
- HTTPS with a Personal Access Token (simpler setup)
- SSH key pair (recommended — more secure, no token expiry issues)
Generate an SSH Key
# Generate a new Ed25519 key (faster and more secure than RSA)
ssh-keygen -t ed25519 -C "jane@yourcompany.com"
# Press Enter to accept default path (~/.ssh/id_ed25519)
# Optionally set a passphrase (adds an extra layer of protection)
# Output creates two files:
# ~/.ssh/id_ed25519 ← your PRIVATE key (never share this)
# ~/.ssh/id_ed25519.pub ← your PUBLIC key (safe to share)
Add to SSH Agent
# Start the SSH agent
eval "$(ssh-agent -s)"
# Add your key to the agent (so you don't type passphrase every time)
ssh-add ~/.ssh/id_ed25519
# macOS: persist key across reboots
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
# View added keys
ssh-add -l
Add Public Key to GitHub
# Copy the public key to clipboard
cat ~/.ssh/id_ed25519.pub
# ssh-ed25519 AAAAC3NzaC1lZDI1NTE5... jane@yourcompany.com
# Add to GitHub:
# GitHub → Settings → SSH and GPG keys → New SSH key
# Paste the output above
Test the Connection
ssh -T git@github.com
# Hi jane! You've successfully authenticated, but GitHub does not provide shell access.
# ✅ Working!
Clone Repositories Using SSH
# Always use SSH URL (not HTTPS) when using SSH keys
git clone git@github.com:yourorg/my-repo.git # ✅ SSH
# Not: git clone https://github.com/yourorg/my-repo.git (would ask for PAT)
# Switch an existing repo from HTTPS to SSH
git remote set-url origin git@github.com:yourorg/my-repo.git
git remote -v # Verify
Signing Commits with GPG (Optional but Professional)
Signed commits prove that a commit really came from you — not from someone who compromised your GitHub account:
# Generate a GPG key
gpg --full-generate-key
# Choose: RSA and RSA, 4096 bits, 1 year expiry
# List your keys
gpg --list-secret-keys --keyid-format=long
# /Users/jane/.gnupg/secring.gpg
# sec 4096R/3AA5C34371567BD2 2026-01-01
# Configure Git to sign all commits
git config --global user.signingkey 3AA5C34371567BD2
git config --global commit.gpgsign true
git config --global tag.gpgsign true
# Export and add public key to GitHub
gpg --armor --export 3AA5C34371567BD2
# GitHub → Settings → SSH and GPG keys → New GPG key
# Paste the output
Signed commits show a green "Verified" badge on GitHub, giving teammates and auditors confidence in commit authenticity.
The Complete ~/.gitconfig
Here's what a well-configured global Git config looks like:
[user]
name = Jane Smith
email = jane@yourcompany.com
signingkey = 3AA5C34371567BD2
[core]
editor = code --wait
autocrlf = input # macOS/Linux
pager = less -FX # Don't open pager for short output
[init]
defaultBranch = main
[pull]
rebase = true
[push]
autoSetupRemote = true # Automatically set tracking on first push
[commit]
gpgsign = true
[diff]
tool = vscode
colorMoved = default # Color moved lines differently from changed lines
[merge]
tool = vscode
conflictstyle = zdiff3 # Better conflict markers (shows common ancestor)
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
[alias]
lg = log --oneline --graph --decorate --all
st = status -sb
undo = reset HEAD~1 --mixed
pushf = push --force-with-lease
whoami = !git config user.name && git config user.email
recent = for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ | head -10
Summary
- Install Git via Homebrew (macOS), apt/dnf (Linux), or winget (Windows)
- Configure identity:
git config --global user.name and user.email — these are embedded in every commit
- Set
pull.rebase = true for a clean, linear history
- Set
core.autocrlf = input (macOS/Linux) or true (Windows) to prevent line ending noise
- Use SSH keys (Ed25519) for GitHub authentication — more secure, no token expiry
- Signed commits (GPG) add a "Verified" badge and cryptographic proof of authorship
- Useful aliases:
git lg for visual graph, git st for compact status, git pushf for safe force-push
In the next lesson, you will master the three-state Git model and the core commit workflow.