Git & GitHub Interview Question #74

What is the difference between merge commit, squash merge, and rebase merge on GitHub?

Undo & Recovery, Tags, Forks, Pull Requests & Code Review Mid-Level Intermediate

Quick Interview Answer

A merge commit preserves the branch's commits and creates a merge commit connecting the histories. Squash merging combines the pull request's changes into a single commit on the target branch.

Detailed Explanation

A merge commit preserves the branch's commits and creates a merge commit connecting the histories. Squash merging combines the pull request's changes into a single commit on the target branch.

Rebase merging reapplies the pull request commits onto the target branch without a merge commit, producing new commit identities. Repository policy determines which methods are allowed, and each method produces a different history shape.

Code Example

# Conceptual Git equivalents vary by workflow:
git merge --no-ff feature

# Local squash concept:
git merge --squash feature

# Local rebase concept:
git rebase main