CS FundamentalsVery hardGATE CS · TCS NQT Prime · Product Company SDE

A long-lived feature branch has fallen far behind main, and its author wants a clean, linear history without the clutter of many intermediate merge commits, and is comfortable rewriting their own branch's history before opening a pull request. Which approach fits best?

  1. A. Merge main into the feature branch repeatedly without ever rebasing
  2. B. Cherry-pick every single commit from main onto the feature branch by hand
  3. C. Delete the feature branch and start over from scratch each time
  4. D. Interactively rebase the feature branch onto the latest main, then force-push the rebased branch (a safe operation here since no one else has based work on it)

Correct answer: D. Interactively rebase the feature branch onto the latest main, then force-push the rebased branch (a safe operation here since no one else has based work on it)

Rebasing onto the latest main gives a clean, linear history as if the feature had been built on the current tip all along; force-pushing is acceptable specifically because the branch is not yet shared with collaborators who have based work on the old commits.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic