THE GITHTML FIELD GUIDE
Choose Git merge or rebase for a collaboration task
Merge integrates histories while preserving existing commits; rebase replays selected commits onto a new base and creates new commit identities. Rebase can simplify an unpublished topic branch, but rewriting commits others already use requires coordination. Choose according to the repository’s policy, preserve local work, and test the combined result either way.
Understand the identity change
A commit records more than a patch: its parent relationship is part of its identity. Replaying the same textual change on a different parent therefore produces a different commit. This is why rebasing is a history rewrite even when the final files look unchanged. A merge instead creates a connection between histories while retaining their existing commit identities.
For a personal, unpublished feature branch, rebasing onto a newer base can make the contribution easier to review. For a branch shared by several contributors, rewriting the commits can disrupt everyone’s local references and pending work. A tidy graph does not compensate for coordination failures. Establish whether anyone else relies on the branch before selecting a strategy.
Inspect divergence before deciding
The commands below inspect the current state and the relationship with origin/main after fetching. They do not perform either integration. Replace the remote and base with the project’s real values. Left and right markers distinguish commits unique to each side, giving you evidence for the decision rather than relying on a generic ahead/behind label.
- Choose merge when preserving shared commit identities and explicit integration history is important, subject to the project’s accepted workflow.
- Consider rebase for commits that are still private to your work and when the project prefers that review shape. Preserve a recovery reference before a significant rewrite.
git status --short --branch
git fetch origin
git log --left-right --oneline HEAD...origin/main
git log --graph --oneline --decorate -20Plan conflicts and verification explicitly
Both approaches can stop for conflicts. A rebase may encounter related conflicts more than once while replaying several commits; a merge resolves the combined integration at its merge point. Read status to identify the active operation and use that operation’s continue or abort command. Do not mix merge, rebase, reset, and cherry-pick commands in an attempt to escape uncertainty.
Afterward, review the resulting history and run relevant tests on the integrated files. If publication would require replacing existing remote history, pause for the team’s explicit procedure instead of treating force-pushing as routine cleanup. You can also postpone integration when the task is only to inspect incoming changes. The right choice is the one that preserves collaborators’ expectations and produces an understandable, verified result, not whichever command appears shorter.
Commit messages should still explain the changes after integration. A linear history with vague messages can be harder to understand than a well-described merge preserving the original development context.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.