← Back to Notes

Git rebase vs merge strategy

Git

Git Rebase vs Merge

Merge

Combines branches, preserving full history.

git checkout main
git merge feature-branch
# Creates a merge commit

History looks like:

A---B---C---M (main, after merge)
     \     /
      D---E   (feature-branch)

Rebase

Replays your commits on top of another branch.

git checkout feature-branch
git rebase main
# Replays feature commits on top of main

History looks like:

A---B---C---D'---E' (feature-branch after rebase)

When to Use

Merge:

  • Public branches that others depend on
  • Preserving exact merge history is important
  • Simple feature branches

Rebase:

  • Cleaning up local commits before merging
  • Keeping feature branches up to date with main
  • Creating a linear history

The Golden Rule

Never rebase commits that have been pushed to a public branch. Only rebase local/private commits.