Ch. 16 · Git & CI/CD

Git Merge Versus Rebase and Shared History

Git Merge Versus Rebase and Shared History. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readbeginnerupdated Oct 3, 2026

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.

More in Git & CI/CD

read ✓Git & CI/CD · easy

Git Detached HEAD

What a detached HEAD is, when it happens, and how to keep commits made in that state.

~2 min readread →
read ✓Git & CI/CD · mid

Git Hooks and Local Automation

Automate checks with client and server hooks, share them through a framework, and enforce the same rules in CI where they cannot be bypassed.

~2 min readread →
esc