Merge combines histories with their existing ancestry; rebase recreates commits on a new base. Choose according to collaboration and history policy.
Before you start
You should understand commits, branches, the working tree and the staging area. Draw the commit graph before changing history. Try commands in a disposable repository with a clean working tree so you can observe exactly which references and files each operation changes.
The practical goal is to reason through this situation: Rebase a private feature branch to replay its changes on current main. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Draw existing ancestry
Identify shared commits and the feature branch’s divergence.
Step 2: Choose integration policy
Merge retains ancestry; rebase recreates feature commits on another base.
Step 3: Protect collaborators
Coordinate any published-history rewrite and keep a recovery reference.
Worked scenario
Rebase a private feature branch to replay its changes on current main.
A private feature has commits F1 and F2 while main advances. Rebasing creates new versions of F1 and F2 with new parents and identities. A merge instead records combined ancestry. Collaborators holding the old feature commits need explicit coordination if those published identities are replaced.
Common mistake
Rewriting shared commits without coordination disrupts collaborators’ references.
Verify the behavior
Inspect the graph before and after each method in a disposable repository.
Interview exercise
Update a shared feature branch.
Answer and reasoning
Prefer a policy-compatible merge or coordinate any rewrite explicitly, preserving a recovery reference.
Continue learning
Compare the scenario with the Git and CI/CD interview questions and test your understanding with the Git and CI/CD MCQs. For terminology and implementation details, consult the reference material.