Skip to content

Instantly share code, notes, and snippets.

@thomaskanzig
Last active April 29, 2025 16:47
Show Gist options
  • Save thomaskanzig/fac1c30f0d1ea2205d76f2a84dc691db to your computer and use it in GitHub Desktop.
Save thomaskanzig/fac1c30f0d1ea2205d76f2a84dc691db to your computer and use it in GitHub Desktop.
Git Rebase vs Git Merge

The main differences between git rebase and git merge:

Git Merge

  • Creates a new "merge commit" that combines changes from both branches
  • Preserves the full history and original branch structure
  • Non-destructive operation (doesn't change existing commits)

Git Rebase

  • Moves your branch's commits to start from the tip of the target branch
  • Creates a linear, cleaner history by reapplying your commits one by one
  • Rewrites commit history (changes commit hashes)

When to use which:

Use merge when:

  • Working on a shared/public branch that others are using
  • You want to preserve the complete history
  • You need to maintain merge context

Use rebase when:

  • Working on a personal/feature branch
  • You want a cleaner, linear history
  • You want to avoid "merge bubbles" in the graph

For updating your feature branch (feature/navigation-section) from another branch (like main):

# If you want a clean history (recommended for feature branches)
git checkout feature/navigation-section
git rebase main

# If others are also working on your feature branch
git checkout feature/navigation-section
git merge main

Rebase is generally preferred for feature branches as it creates a cleaner history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment