Course contentsShow
← Data Science
Lesson 2026 of 2,14546. Version Control with GitFree lesson

Merge Strategies: Merge vs Squash vs Rebase

Different ways to integrate pull requests into the main branch and when to use each merge strategy.

Merge Strategies: Merge vs Squash vs Rebase

You'll learn: The three main strategies for integrating pull requests into your main branch and when each is most appropriate for your workflow.

Understanding Your Options

When a pull request is approved, you have three primary ways to integrate those changes into the main branch: merge, squash and merge, and rebase and merge. Each strategy has different effects on your repository's commit history.

The Three Strategies

Regular Merge

Creates a merge commit that ties together the feature branch history with the main branch. All individual commits from your feature branch remain visible in the history.

Use when: You want to preserve the complete development history of a feature, especially for complex work where the commit-by-commit story matters.

Squash and Merge

Combines all commits from the feature branch into a single commit on the main branch. The individual commits disappear from the main branch history.

Use when: Your feature branch has messy commits (WIP commits, typo fixes) and you want a clean, linear history. Perfect for small features where the journey doesn't matter—only the final result.

Rebase and Merge

Replays each commit from the feature branch onto the main branch without creating a merge commit. Maintains individual commits but rewrites them as if they were made directly on main.

Use when: You want to preserve individual commits but maintain a perfectly linear history without merge commits. Common in projects that value clean, sequential history.

The Practical Impact

Think of merge strategies like different ways to tell a story: merge shows every draft and revision, squash gives you the polished final version, and rebase presents a clean narrative as if it happened sequentially.

Key Takeaway: Choose merge for transparency, squash for simplicity, and rebase for linear history—your team's workflow and project complexity should guide the decision.