Git merge vs rebase
Same starting point, two ways to bring main's work into your branch. Watch what happens to the history, the commit hashes, and the conflicts.
Tweak it
Break it
Normal run: the two branches touched different files, so Git combines them without asking.
What to notice
- Merge ties the two histories together with one new merge commit that has two parents. Nothing existing is changed, so every hash stays the same, but the graph keeps its branches.
- Rebase replays your commits one by one on top of main. The history is a straight line, but each replayed commit is a new commit with a new hash; the old ones are abandoned (dashed).
- Add more commits to feature and watch rebase rewrite all of them. Merge always adds exactly one.
- Break it: with overlapping edits, merge asks you to resolve once. Rebase can stop at each replayed commit that touches the same lines. In this toy every feature commit does.
- Rule of thumb: rebase your own unpublished work; don't rebase commits other people already have, since their copies will no longer match.
- Hashes in the picture come from a small toy hash, not SHA-1/SHA-256.