Merge vs Rebase: Choose the Right History Strategy
Same files can mean different history
In the first fixture, merging the original feature into main with --no-ff creates a two-parent commit. Rebasing a copy of feature onto main and fast-forwarding produces a linear chain. The final tracked trees match in this conflict-free example, but the original feature commits are ancestors of the merge result, not the rebased result. Neither graph by itself proves the software is correct.
git diff --exit-code merged-result rebased-resultgit log --graph --oneline --allChoose based on ownership
For a published team branch, preserving existing identities is usually the safer choice; merge or use the agreed review workflow. For a private topic that nobody depends on, rebase can give a clearer linear patch series. Interactive rebase (git rebase -i) can reorder, combine or edit selected commits; it also rewrites history and is covered in a later batch.
Remote integration is a separate choice
git pull --rebase fetches then rebases according to the selected upstream. On a private fork topic, you can instead fetch upstream and explicitly rebase onto the inspected upstream/main. Do not routinely rewrite a shared fork main or force push. If a normal push refuses, inspect divergence and coordinate; a local rescue branch does not protect collaborators from history changes.
Practice
Choose a strategy for a shared release branch and a private two-commit feature. Explain your choice using ownership, ancestry, final file content and project policy. For both, run project tests after integration; the lab checks text and graph only, not a hosted pull request or arbitrary application.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Merge vs Rebase: Choose the Right History Strategy — knowledge check
Reason about safe rebase and history integration.
Which strategy preserves original feature ancestry in the divergent fixture?
Can equal final trees have different commit graphs?
Which branch is the safer candidate for ordinary history rewriting?
What does pull --rebase combine?
What is still needed after integration?