C.W.K.
Stream
Lesson 05 of 05 · published

Identity, Defaults, and .gitignore

~18 min · config, gitignore, setup

Level 0Untracked Rookie
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Identity, defaults, and the ignore file

Three pieces of setup outlive every project: who you are in commits, what defaults you accept, and what you refuse to track. Skip these and you will rediscover them as bugs later — wrong author on years of commits, surprise master branches, secret tokens leaked into history.

Git embeds your name and email in every commit. Set them globally once. The email does not need to be your real one — many people use the GitHub noreply address to avoid scraping. While you are there, set init.defaultBranch to main, set a sensible default editor, and let Git pick the modern pull.rebase behavior so blind git pull stops creating mystery merges. Configuration has three layers — system, global, local — and local always wins. git config --list --show-origin tells you which file each value came from, which is gold for debugging surprises.

.gitignore is the answer to "I do not want this in history." It is just a file in the repo with one pattern per line: build outputs, dependency folders, OS cruft, editor swap files, and — critically — secrets like .env, private keys, and credential dumps. The trap: .gitignore only affects untracked files. If you committed .env once, it stays tracked even after you add it to ignore. You must git rm --cached .env first. And if it ever held a real secret, treat it as compromised and rotate the secret — Git history is forever, even after deletion.

One more habit: set up SSH keys for at least one host (GitHub by default). HTTPS works, but SSH plus an agent eliminates daily password prompts and is the standard developer experience. ssh-keygen -t ed25519 -C "you@example.com", copy the .pub half to GitHub, and you will not type credentials for clones again.

Code

One-time global setup·bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global pull.rebase true
git config --global core.editor "code --wait"  # or vim, nano, etc.

# Where did each value come from?
git config --list --show-origin
A starting .gitignore·text
# Build & deps
node_modules/
dist/
build/
__pycache__/
*.pyc

# Editor & OS
.vscode/
.idea/
.DS_Store
Thumbs.db
*.swp

# Secrets — never commit these
.env
.env.*
*.pem
*.key
credentials.json
I already committed a secret. Now what?·bash
# Stop tracking the file (keeps it on disk)
git rm --cached .env
echo '.env' >> .gitignore
git add .gitignore
git commit -m "Stop tracking .env and ignore it going forward"

# IMPORTANT: the secret is still in older commits.
# Rotate it. Old history-rewrite tools (git filter-repo, BFG)
# can scrub it, but assume any leaked secret is compromised.

External links

Exercise

Run git config --list --show-origin on your real machine and read the output. Decide on three settings to add or correct (name, email, default branch, pull behavior, editor). Set them globally. Then create a fresh repo with git init, add a starter .gitignore based on the language you actually use, and commit it. Confirm git status ignores at least one path you intentionally don't want tracked.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.