πŸ“š What We Learned (Concise List)

Core Commands:

πŸ”§ History Manipulation:

  • git rebase - Move commits to new base (clean history)
  • git rebase -i - Interactive: squash, reword, reorder commits
  • git reset --soft/mixed/hard - Undo commits (careful with β€”hard!)
  • git revert - Undo safely (creates new commit, keeps history)

πŸ’ Moving Commits:

  • git cherry-pick <commit> - Copy specific commit to current branch
  • git stash / git stash pop - Temporarily save uncommitted work

πŸ†˜ Safety & Recovery:

  • git reflog - See ALL history, recover β€œdeleted” commits
  • git <command> --abort - Cancel merge/rebase/cherry-pick
  • git reset --hard HEAD@{n} - Time travel using reflog

πŸ‘₯ Collaboration:

  • git pull --rebase - Get updates + rebase your work on top
  • git push --force-with-lease - Safer force push
  • Never force push shared branches!

πŸ” Debugging:

  • git bisect - Binary search to find bug-causing commit

Golden Rules:

βœ… SAFE for shared branches:

  • pull, merge, revert, commit

⚠️ DANGEROUS for shared branches:

  • reset, rebase, force push, commit --amend

πŸ”‘ Key Principle:

β€œIf it’s pushed and others have it, DON’T rewrite history!”


Emergency Procedures:

ProblemSolution
Wrong commit message (not pushed)git commit --amend
Wrong branchCreate branch, reset main
Lost commitsgit reflog β†’ git reset --hard HEAD@{n}
Bad merge in progressgit merge --abort
Production brokengit revert <bad-commit>
Secrets pushedChange passwords FIRST! Then filter history
Can’t push (remote ahead)git pull then git push

Best Practices:

  1. πŸ”’ Never commit secrets - use .gitignore and .env files
  2. πŸ“ Write clear commit messages - future you will thank you
  3. πŸ”„ Pull before push - stay in sync with team
  4. πŸ§ͺ Test before merging - broken main = angry team
  5. πŸ’¬ Communicate - before force pushing or rebasing shared branches