04

Lesson 4 of 12

Git First-Time Setup

Configure Git with your identity, set useful aliases, and create a global .gitignore that keeps your repos clean.

~10 min·Mac
04 / 12Git First-Time Setup

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 falsegit pull uses 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

CommandWhat it does
git initStart tracking a folder with Git
git sSee what changed (short)
git statusSee what changed (detailed)
git add .Stage all changes
git cm "message"Commit with a message
git lgView recent history as a graph
git pushUpload commits to GitHub
git pullDownload changes from GitHub
git sw -c feature/nameCreate a new branch
git unstage file.tsUnstage a file

In the next lesson we'll connect Git to GitHub using SSH.

Knowledge Check

Answer all questions to mark this lesson complete.

Q1Why do you need to set your name and email in Git?

Q2What is a global .gitignore for?

Setting Up Ghostty Terminal
GitHub Account & SSH Authentication