Skip to content

Git Happens - Pro Tips & Pitfalls

Even the smoothest committers occasionally crash into a merge wall, forget to pull, or nuke main by accident.
That’s okay — Git happens. What matters is how we recover, learn, and prevent it next time.

This chapter is part wisdom, part cautionary tale, and all Professor Solo attitude.


💡 Top Tips for a Happier Git Life

Section titled “💡 Top Tips for a Happier Git Life”
💡 TipCommand / HabitWhy It Matters
Pull before you pushgit pull --rebaseAvoids “non‑fast‑forward” conflicts
Review before you commitgit diff --stagedCatch typos & stray files early
Keep .gitignore tidy.DS_Store, node_modules/, /distKeeps repos lean and clean
Stash before switchinggit stash; git switch branchPrevents lost WIP when changing branches
Check your remotesgit remote -vConfirms where your pushes go
Clean merged branchesgit branch --merged → git branch -dReduces clutter
Commit small, commit oftenEasier rollbacks & clearer history
Write meaningful messagesgit commit -mSaves future‑you from confusion

💡 Professor Solo’s Pro Tip:
Git is a memory system — feed it details, not drama.


⚠️ Common Pitfalls (and How to Climb Out)

Section titled “⚠️ Common Pitfalls (and How to Climb Out)”

🚫 Accidentally deleted everything?

Section titled “🚫 Accidentally deleted everything?”

Don’t panic. Git remembers.

Terminal window
git reflog
git switch -c rescue <hash>

You’re back in business.


🤦 Committed secrets or passwords?

Section titled “🤦 Committed secrets or passwords?”

Rotate keys immediately and add sensitive files to .gitignore.
Use environment variables next time.

Terminal window
echo".env">> .gitignore
git rm --cached .env
git commit -m "Remove .env from repo"

🌀 Forgot to pull before pushing?

Section titled “🌀 Forgot to pull before pushing?”

Git will yell: “non‑fast‑forward” error.
Just pull, merge, and push again.

Terminal window
git pull --rebase
git push

Create a fresh branch from a safe commit and start over:

Terminal window
git switch -c fix/main <commit‑hash>

Then merge it back once it’s stable.

💡 Professor Solo says:

“We don’t fear mistakes — we version control them.”


  • 🕒 Commit at logical milestones (“feature complete,” not “end of day”)
  • 🗂️ Use branches like folders — keep work isolated and organized
  • 🧹 Prune remotes you don’t need (git remote remove <name>)
  • 🪣 Never commit build outputs or secrets
  • 🧘 Trust Git, but verify your pushes (git status, git log)
  • 🪐 Always add a README — even for yourself

💡 Professor Solo’s Pro Tip:
“Before you hit push, ask — am I pushing progress or panic?”


🧠 Advanced Wisdom for the Brave

Section titled “🧠 Advanced Wisdom for the Brave”
  • Use git cherry‑pick to grab just one commit from another branch
  • Use git blame to trace who changed what (line accountability, not judgment!)
  • Use git bisect to find which commit introduced a bug (fast debugging)
  • Use git log --graph --oneline to visualize branch history
  • Use git config --global alias.co checkout for shorthand speed

⚙️ Professor Solo’s Challenge:
Make your own Git aliases and share them with the class.
Efficiency is contagious.


✅ Mission Check: From Pitfall to Power Move

Section titled “✅ Mission Check: From Pitfall to Power Move”

By now, we can:
1. Avoid common Git blunders (gracefully)
2. Recover lost work with reflog and reset
3. Prevent disasters using .gitignore and smart branching
4. Build productive Git habits that last
5. Laugh off mistakes (because we can fix them)


💡 Professor Solo says:

“In Git we trust — but we still make backups.”
Keep your branches clean, your commits meaningful, and your sense of humor intact.”