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."Some files must never be tracked. And your laptop alone is not backup — GitHub is where the real safety net lives.
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.".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:
# 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
! 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.# 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
| Command | When to use it |
|---|---|
git init | Starting a brand-new project from scratch |
git clone | Joining an existing project already on GitHub |
git remote add origin | Connecting an existing local repo to a new GitHub repo |
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.