1. Workflows: Git Flow vs GitHub Flow
How should you merge and deploy code? Your branching strategy depends on your team's size and product characteristics.
"Rebase is powerful magic for rewriting history. But you should never cast this spell on a branch shared with others." – Senior DevOps Engineer
2. The Eternal Debate: Merge vs Rebase
There are two primary ways to integrate changes from one branch into another. The resulting history is entirely different.
3. Don't Panic! Resolving Merge Conflicts
A Conflict occurs when two developers modify the exact same line in the same file. Don't worry; there is a formula to solve this.
4. Advanced Lifesaver Commands
These are advanced skills for when you've blown up your code or just want to "steal" a specific commit from someone else's branch.
- 🍒 Cherry-pick: Grab one specific commit from another branch and apply it to yours.
git cherry-pick <commit-hash> - 📦 Stash: Temporarily shelve your uncommitted work. Perfect for when you urgently need to switch branches.
git stash(Save) ➔git stash pop(Retrieve) - ✏️ Amend: Modify the very last commit if you made a typo in the message or forgot to add a file.
git commit --amend - 🚑 Reflog: The Ultimate Time Machine. A log of every action you've taken in Git. You can even recover commits you deleted with a hard reset.
git reflog(Find hash) ➔git reset --hard <hash>
Conclusion: Quick Summary Table
| Situation / Goal | Command | Notes |
|---|---|---|
| Merge & preserve history | git merge <branch> |
Creates a Merge Commit |
| Clean, linear merge | git rebase <branch> |
Never use on public branches |
| Cancel a conflicting merge | git merge --abort |
Restores pre-merge state |
| Temporarily save work | git stash |
Hides unstaged changes |
| View all action history | git reflog |
The last hope for recovery |