Git Academy

Intermediate · 6 min read

Merge or rebase?

The eternal debate, settled with one simple rule.

Merge: join two histories

Creates a merge commit that ties both branches together. Nothing is rewritten, which makes it safe everywhere, at the cost of a busier history.

Safe
$ git switch main
$ git merge feature/login-page

Rebase: replay your commits on top

Takes your commits and re-applies them on the latest main, as if you had started from there. The history is linear, but every rebased commit gets a new hash.

Safe
$ git switch feature/login-page
$ git rebase main

The golden rule

Rebase your own branches, merge shared ones. Never rebase commits that other people have already pulled: their copies would diverge from yours.