SteelReed

Search

Search posts, questions…

DevOps & CloudQuestion 6 / 35

Middle

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.

no: private branchyes: shared branchyesDoes anyone else use thebranch?Rebase onto mainstraight historyMerge or squash merge viaPRPushed before?push --force-with-lease

3 points to say:

  1. Merge keeps true history; rebase gives a straight history but changes hashes; squash turns a PR into one commit.
  2. Rebase private branches, merge/squash into shared ones; rebase is only dangerous when it rewrites shared history.
  3. Force push only with --force-with-lease; for conflicts that repeat during rebase, enable rerere.

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.