Merge vs rebase vs squash: one pull request, three histories

By Christophe Paka · Facts checked on 30 October 2026

Your pull request is approved. The green button has a small arrow, and it opens three choices. Your team says "rebase is required". A thread with hundreds of replies argues the opposite. You still do not see what rebasing adds if the pull request gets squashed anyway.

Press the wrong one and you fight the same conflicts twice, or break a colleague's copy of a shared branch. Merge vs rebase vs squash is easier as a picture. The figure takes one branch with three commits and shows what lands on main after each button.

A commit graph: main has A and B, a branch adds C, D and E. Merge commit keeps C, D, E plus a merge commit M with two parents. Squash and merge adds one commit S. Rebase and merge adds C', D', E' in a straight line, with new IDs.
Figure 3.2 One pull request, three merge methods: the same three commits arrive whole, as one, or replayed with new IDs.
Use this diagram on your site

Free to share in your blog post, docs, course or slides, as long as the credit link stays. Paste the code below where the figure should go.

How to read this figure

  1. Read the starting picture. At the top, main holds commits A and B. Your branch starts from B and carries three commits: C, D and E. All three panels below start from this same picture; only what lands on main differs.

  2. Panel 1: merge commit. The default button, Merge pull request, keeps C, D and E and adds a merge commit M with two parents: the last commit on main and the last on your branch. History is complete. Use it when each commit means something on its own.

  3. Panel 2: squash and merge. Squash and merge turns all three commits into one new commit S on main. The branch commits never land on main. Three commits in, one out: one line of main per shipped change. It works best for short lived branches.

  4. Panel 3: rebase and merge. Rebase and merge replays each commit on top of main, in a straight line, with no merge commit. They come out as C', D' and E'. Each gets a new SHA, the ID git computes from a commit's content.

  5. Read the warnings under panel 3. Rebase always updates committer information and creates new SHAs, and it drops commits that were empty to begin with. New IDs are why you never rebase a branch someone else also pushes to. If a rebase stops on a conflict, read the conflict markers.

Key takeaways

  • Pick the button by what your group wants to read later, not by habit.
  • Never rebase a branch a colleague also pushes to; rebase only branches you alone use.
  • After a squash merge, start the next change on a fresh branch from main.

Worked example: pull request #3 through all three buttons

In pocket-ledger, the expense tracker the book builds, main holds A and B. Pull request #3, Add monthly total, adds C (add total function), D (fix rounding) and E (test the total). Run git log --oneline after each merge.

  1. Merge pull request: 4 new commits on main. The log lists M, E, D, C, B, A.
  2. Squash and merge: 1 new commit on main. The log lists S, B, A. The fix rounding commit has vanished into S.
  3. Rebase and merge: 3 new commits with new IDs. The log lists E', D', C', B, A, with no merge commit.

Result: Same work, three histories. If your group reads every commit, merge or rebase keeps them. If it wants one clean line per change, squash. If a button is missing, the repository switched it off in its settings, under Pull Requests.

Questions readers ask

What does rebasing add if every pull request is squashed anyway?

Nothing on main. The squash replaces your commits with one, so their order and IDs no longer matter there. Rebasing matters only where a group uses the Rebase and merge button and reads each commit.

Is rebase dangerous?

Not in itself. Rebasing a branch only you use is fine. On a shared branch it forces a force push: your colleague still holds the old commits, the branch now holds new ones with new IDs, and their copy no longer matches.

Which merge button should I use?

Working alone, or in a small group with messy commits: squash and merge. A group whose commits each mean something: merge commit. A group that wants a straight history and keeps commits tidy: rebase and merge. If your repository allows only one, use that one.

Why do I get the same conflicts again after a squash?

You kept working on the branch after it was squashed and opened a new pull request from it. The old commits came along again. GitHub warns this can make you resolve the same conflicts more than once. Start each change on a fresh branch from main.

Sources: About pull request merges (GitHub Docs); git-rebase (git documentation).

This figure is from GitHub Made Crystal Clear, chapter 3.

The chapter builds the idea step by step, with recipes you can follow, a Try it to check yourself, and every source.

Get the book

All diagrams