How do merge and rebase differ? When should you squash, and when is force pushing safe?
Short answer
Merge keeps history as it happened, joining two branches with a merge commit (or a fast-forward). Rebase replays your commits on top of the target branch as new commits with new hashes, giving a straight history.
3 points to say:
- Merge keeps true history; rebase gives a straight history but changes hashes; squash turns a PR into one commit.
- Rebase private branches, merge/squash into shared ones; rebase is only dangerous when it rewrites shared history.
- Force push only with
--force-with-lease; for conflicts that repeat during rebase, enablererere.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.