What is the difference between merge and rebase?medium

Type
conceptual
Topic
branching
Frequency
very common
Tags
branching
Answer

Merge creates a new merge commit that ties two branch histories together. Rebase replays your commits on top of another branch, rewriting history to produce a linear sequence.

Explanation

Use merge when preserving the full branch history matters (e.g., long-lived feature branches). Use rebase to keep a clean, linear history before integrating into main. Never rebase commits already pushed to a shared branch - it rewrites SHAs and forces collaborators to reconcile diverged histories.

Follow-upWhen would you choose one over the other on a team?