π 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 commitsgit 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 branchgit stash/git stash pop- Temporarily save uncommitted work
π Safety & Recovery:
git reflog- See ALL history, recover βdeletedβ commitsgit <command> --abort- Cancel merge/rebase/cherry-pickgit reset --hard HEAD@{n}- Time travel using reflog
π₯ Collaboration:
git pull --rebase- Get updates + rebase your work on topgit 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:
| Problem | Solution |
|---|---|
| Wrong commit message (not pushed) | git commit --amend |
| Wrong branch | Create branch, reset main |
| Lost commits | git reflog β git reset --hard HEAD@{n} |
| Bad merge in progress | git merge --abort |
| Production broken | git revert <bad-commit> |
| Secrets pushed | Change passwords FIRST! Then filter history |
| Canβt push (remote ahead) | git pull then git push |
Best Practices:
- π Never commit secrets - use
.gitignoreand.envfiles - π Write clear commit messages - future you will thank you
- π Pull before push - stay in sync with team
- π§ͺ Test before merging - broken main = angry team
- π¬ Communicate - before force pushing or rebasing shared branches