Set your Git identity
Git stamps your name and email onto every commit you make. Run these commands with your own name and email:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Set a few more sensible defaults:
git config --global init.defaultBranch main
git config --global pull.rebase false
git config --global core.editor "code --wait"
git config --global color.ui auto
What each one does:
- init.defaultBranch main — new repos start with a branch called
main(the modern standard) - pull.rebase false —
git pulluses merge instead of rebase (simpler for beginners) - core.editor — VS Code opens for any command that needs a text editor
- color.ui auto — colorizes terminal output from Git
Verify everything was saved:
git config --list --show-origin
Add Git aliases
Aliases are shortcuts for long commands. These are especially useful when you're running Git commands dozens of times a day:
git config --global alias.s "status --short"
git config --global alias.st "status"
git config --global alias.sw "switch"
git config --global alias.cm "commit -m"
git config --global alias.lg "log --oneline --decorate --graph --all -20"
git config --global alias.unstage "restore --staged"
git config --global alias.last "log -1 --stat"
Now instead of git status you can type git s, and instead of that long git log command you can type git lg.
Try them out
After setting aliases, try git lg in any repo. You'll get a beautiful one-line graph of your commit history.
Create a global .gitignore
Every Mac generates .DS_Store files — hidden files macOS uses for folder settings. You never want these in your repos. A global gitignore keeps them out of every project automatically.
mkdir -p ~/.config/git
Open the file in a text editor:
open -e ~/.config/git/ignore
Paste this and save:
# macOS
.DS_Store
.AppleDouble
.LSOverride
# Editor
.vscode/*
!.vscode/extensions.json
!.vscode/settings.json
.zed/settings.json
# Environment variables (never commit these)
.env
.env.*
!.env.example
# Logs
*.log
# Local scratch folders
scratch/
tmp/
.temp/
Git picks this up automatically — no extra config needed.
Never commit .env files
Your .env files contain secret API keys, passwords, and database URLs. The global gitignore above blocks them. But always double-check with git status before committing to a new project — secrets in public repos are a serious security risk.
The essential Git commands
| Command | What it does |
|---|---|
git init | Start tracking a folder with Git |
git s | See what changed (short) |
git status | See what changed (detailed) |
git add . | Stage all changes |
git cm "message" | Commit with a message |
git lg | View recent history as a graph |
git push | Upload commits to GitHub |
git pull | Download changes from GitHub |
git sw -c feature/name | Create a new branch |
git unstage file.ts | Unstage a file |
In the next lesson we'll connect Git to GitHub using SSH.