🚫 .gitignore & Remote Repos

Some files must never be tracked. And your laptop alone is not backup — GitHub is where the real safety net lives.

1. The Story: A Near-Miss

📖 Alex types git add . and is about to commit his .env file — which contains his real MongoDB password. His senior stops him just in time: "Wait! Never commit secrets. Set up .gitignore first."
⚠️ Why this is scary: if a secret ever gets committed, deleting the file later does NOT remove it — Git history is visible forever. Automated credential scanners find exposed secrets within minutes of a push. If it happens: rotate every exposed password immediately. (Chapter 9 covers the emergency cleanup.)

2. .gitignore — Watch It Filter Files Live

.gitignore is a plain text file of patterns. Anything matching a pattern becomes invisible to Git — it never shows in git status, and git add . silently skips it. Click each file to test it against Alex's .gitignore:

📄 .gitignore contents (Alex's actual file)
# Environment variables — NEVER commit real .env files!
.env
.env.local
# But DO track the template:
!.env.example
# Python compiled files & virtual envs
__pycache__/
*.pyc
venv/
# Logs, IDE files, OS junk
*.log
.vscode/
.DS_Store
app.py .env .env.example __pycache__/app.cpython-311.pyc requirements.txt
5 files exist on disk. Which ones will Git see?
The ! trick: .env is ignored, but !.env.example means "except this one" — so the safe template still gets tracked and shared with the team, while the real secrets file never can.

3. Remote Repositories — Your Laptop Is Not Backup

📖 "Push it to GitHub," Alex's manager says. "Then your work is safe, and the team can see it."
💻 Alex's laptop local repo: taskmanager/.git remote name: "origin" git push -u origin main git pull / clone ☁️ GitHub — "origin" github.com/alex-mercer/taskmanager safe even if the laptop dies · visible to the team
# Link local repo to a NEW GitHub repo:
git remote add origin https://github.com/alex-mercer/taskmanager.git
git remote -v                    # verify it was added
git push -u origin main          # -u = remember this for future "git push"

# Joining an EXISTING project instead — clone it:
git clone https://github.com/alex-mercer/taskmanager.git
CommandWhen to use it
git initStarting a brand-new project from scratch
git cloneJoining an existing project already on GitHub
git remote add originConnecting an existing local repo to a new GitHub repo
📡 Analogy: origin is just a nickname — like saving a contact as "Mom" instead of typing her phone number every time. You could name a remote anything, but by convention the main one is always called origin.
🔓 You're reading a free chapter of Git — the first two are open.
Unlock the rest of this course with a one-time payment.
Unlock this course →
🔓 See course prices