Running git rebase main while on a feature branch replays that branch's commits on top of the latest commit on main, bringing the feature branch up to date without creating a merge commit.
Key Points: • Rebase moves the feature branch's commits one at a time onto the current tip of main, rewriting their commit hashes in the process. • If a commit conflicts with changes already on main, the rebase pauses so you can resolve that specific conflict before continuing. • git rebase --continue moves to the next commit once a conflict is resolved, and git rebase --abort cancels the whole operation and restores the branch to its pre-rebase state. • The result is a clean, linear history, in contrast to merging main into the feature branch, which would add an extra merge commit. • This should only be done before the feature branch is shared or after coordinating with anyone else working on it, since it rewrites commit hashes.
Example: A feature branch is five commits behind main; running git rebase main replays those five commits on top of main's latest commit, resolving one small conflict along the way, resulting in a clean, linear history ready for review.
Code Example:
git checkout feature-branch
git rebase main
# resolve any conflicts, then
git rebase --continueInterview Tip: A concise interview answer is:
"I'd check out the feature branch and run git rebase main, which replays my commits on top of main's latest commit instead of creating a merge commit. If a conflict comes up partway through, I resolve it and run git rebase --continue to finish."