Microsoft Certified: DevOps Engineer ExpertConfigure processes and communicationsMedium
A software development team is adopting Git for version control and wants to enforce a strict linear history in their main branch. They want to avoid merge commits in the main branch to keep the commit history clean and easy to follow. Which Git strategy should they primarily use when integrating changes from feature branches into the main branch?
- AMerge commit strategy
- BRebase strategy
- CSquash merge strategy
- DFast-forward merge strategy
Show answer & explanationAnswer & explanation
Correct answer: B. Rebase strategy
The rebase strategy is ideal for maintaining a strict linear history because it reapplies commits from a feature branch onto the latest commit of the main branch, effectively rewriting the feature branch's history to appear as if work was done directly on the main branch, thus avoiding explicit merge commits.
Why the other options are wrong
- A. A merge commit strategy creates an explicit merge commit, which is precisely what the team wants to avoid to maintain a linear history.
- C. A squash merge strategy combines all commits from a feature branch into a single commit before merging, which keeps the main branch history clean but still creates a merge commit (unless fast-forwarded), and doesn't preserve the individual commits from the feature branch.
- D. A fast-forward merge strategy is only possible if the main branch has not diverged from the feature branch's base, which is rarely the case in active development, and it still technically performs a merge without a merge commit if applicable, but rebase is the primary method for enforcing linearity in all cases.
Git Rebase Strategy
Git rebase reapplies commits from one branch onto another, effectively rewriting commit history to create a linear progression without merge commits. It's used to keep feature branches up-to-date with the main branch and to maintain a clean, linear history on the main branch.
- Rewrites commit history.
- Creates a linear commit history.
- Avoids merge commits.
- Can be dangerous if used on shared branches.
Memory trick: Branch merges must be clean, like a clear path.