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?
- AMerge (no fast-forward)
- BRebase and Merge
- CFast-Forward Merge
- DSquash and Merge
Show answer & explanationAnswer & 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.