Advanced Git: Rebase vs. Merge
Keep your history clean. Understanding when to use `git merge` and when to reach for `git rebase`.
Git is more than just commit and push. As projects grow, history management becomes vital.
The Merge Strategy
git merge feature-branch
- Pros: Non-destructive. Preserves true history.
- Cons: Creates "merge commits" that clutter the logs.
The Rebase Strategy
git rebase main
- Pros: Linear history. Looks like you coded everything sequentially. Easier to read.
- Cons: destructive. Rewrites history. NEVER rebase a public branch.
Cherry Picking
Sometimes you need just one specific commit from another branch, not the whole thing.
git cherry-pick <commit-hash>
This applies that specific change to your current branch. Useful for hotfixes.
Interactive Rebase
The ultimate cleanup tool.
git rebase -i HEAD~3
This lets you squash typos, reorder commits, and edit messages before pushing.