Learning navigation

Code with Animation

Rebase vs Merge

Understanding the difference between a clean linear history and a complete contextual history.

Version Control6 min readConcept 24 of 29

Merge vs Rebase

Merge: A non-destructive operation that takes the contents of a source branch and integrates them into a target branch by creating a single new 'merge commit.'

Rebase: A history-rewriting operation that moves the entire feature branch to begin on the tip of the main branch. Instead of a merge commit, it creates brand new commits for each original commit.

Why it matters

Choosing between rebase and merge dictates a team's collaboration convention.

Merge prioritizes a Complete History: It shows exactly when and how features were integrated, but can pollute the history with extra merge commits.

Rebase prioritizes a Clean History: It eliminates unnecessary merge commits, creating a pristine timeline that simplifies debugging (e.g., using git bisect).

How it works

Merge integrates branches by creating a new commit that ties together the histories of both branches. Visually, this creates a diamond shape in the commit graph.

Rebase detaches the feature branch commits from their original starting point and re-applies them one-by-one onto the latest commit of the target branch. Visually, this results in a perfectly linear line.

Compare merging and rebasing

Select an integration method and follow how it changes the shape of the history.

$ git switch main
$ git merge feature
Preview: two histories will connect.

Connect histories

BMF1F2X

Intermediate geometry is an illustration, not a partially created Git commit.

This comparison assumes a conflict-free divergent history. Merge preserves the original feature commits; rebase creates new commits on main. The slider controls a local visual preview.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1What is the defining characteristic of a `git merge` operation compared to `git rebase`?
  2. 2Why do many development teams prefer rebasing over merging for local feature branches?
  3. 3According to the 'Golden Rule of Rebasing', when should you NEVER use `git rebase`?

Remember this

  • Merge creates a non-destructive merge commit (diamond shape).
  • Rebase rewrites history to create a linear path.
  • Merge preserves complete context; rebase prioritizes clean history.
  • Never rebase a public branch that others are using.

Done with this concept?

Mark it complete to track your progress. No login needed.