Microsoft Certified: DevOps Engineer ExpertConfigure processes and communicationsMedium

A software development team is practicing Continuous Integration (CI) and wants to ensure that all code merged into the `main` branch is always deployable. They have implemented automated unit tests, integration tests, and static code analysis. To further strengthen their quality gate and ensure a clean commit history, they want to enforce that every pull request passes all these checks and is then squashed into a single commit before merging. Which pull request merge strategy, combined with branch policies, would best achieve this?

  1. AMerge (no fast-forward)
  2. BRebase and Merge
  3. CFast-Forward Merge
  4. DSquash and Merge
Show answer & explanation

Correct answer: D. Squash and Merge

The 'Squash and Merge' strategy combines all commits from a feature branch into a single new commit on the target branch. This creates a clean, linear history for the main branch, making it easier to revert changes and ensuring that each merge represents a complete, tested feature, which aligns with the goal of a clean, deployable `main` branch.

Why the other options are wrong

  • A. Merge (no fast-forward) creates a merge commit, preserving the full history of the feature branch, which can lead to a cluttered history if many small commits are made.
  • B. Rebase and Merge reapplies commits from the feature branch on top of the target branch, creating a linear history but retaining individual commits, which doesn't meet the requirement of a single commit per pull request.
  • C. Fast-Forward Merge moves the target branch pointer forward to the feature branch's head if there are no diverging commits, which is not always possible and doesn't enforce a single commit per pull request.

Squash and Merge Strategy

A Git merge strategy that combines all commits from a source branch into a single new commit on the target branch, creating a clean, linear history.

  • Simplifies Git history by reducing noise.
  • Each merged PR becomes a single logical change.
  • Facilitates easier reverts of entire features.
  • Often used with pull requests to maintain a clean main branch.

Memory trick: Squash squashes commits clean.

More Configure processes and communications questions