Tired of catching bugs in code review? Git hooks automatically validate code before it even reaches the repository. #!/bin/bash # .git/hooks/pre-commit # Exit immediately if any command fails set -e echo “🚀 Running pre-commit checks…” # 1. Check for debugging statements echo “🔍 Checking for console.log statements…” if git diff –cached –name-only | xargs grep […]
Tag: git best practices
Git: Find and Remove Sensitive Data from Entire Repository History
Accidentally committed API keys or passwords? Deleting the file in a new commit doesn’t remove it from history. Here’s how to purge it completely. ⚠️ The Problem: # You committed config.json with API key git add config.json git commit -m “Add config” git push # Then realized mistake and deleted it git rm config.json git […]
Git: Undo Last Commit Without Losing Changes (3 Different Scenarios)
Committed too early or to wrong branch? Here’s how to undo commits without losing your work, depending on whether you’ve pushed or not. Scenario 1: Undo Last Commit (Not Pushed Yet) # Keep changes in working directory (most common) git reset –soft HEAD~1 # Now your changes are uncommitted, ready to re-commit # Use case: […]
Recover Deleted Git Commits Even After Hard Reset (It’s Not Gone)
Accidentally did ‘git reset –hard’ and lost hours of work? Your commits aren’t deleted – they’re just orphaned. Here’s how to find them. The Magic Command – Reflog: git reflog This shows every HEAD movement in your repository, even deleted commits. Output looks like: a1b2c3d HEAD@{0}: reset: moving to HEAD~3 e4f5g6h HEAD@{1}: commit: Added user […]
The Hidden Cost of Large Commits (It’s Not Code Review)
Big commits don’t just slow reviews. Real damage Breaks git bisect Makes rollback risky Hides causal relationships Rule One commit = one reason. Mental model If you can’t describe the commit in one sentence, it’s too big.
Stop Using git pull (Yes, Really)
git pull = fetch + mergeYou lose control. Better git fetch git rebase origin/main Why Cleaner history Fewer merge commits Easier rollback Rule Explicit is safer than automatic.




