CodecPath

Guide

GitHub Squash and Merge: Choose a History Policy

Squash disposable development commits, but preserve merge commits when your team needs commit-level debugging, selective reverts, or backports.

CodecPath editors7 min read
Merge commitKeeps hashes and branchtopologySquash mergeLeaves one permanentchange unitRebase and mergeKeeps steps but rewriteshashes
Identical file results can leave radically different evidence for debugging, reverts, and backports.

Merge commit vs squash: which policy fits the repository?

Choose by maintenance cost.

Squash a pull request when its individual commits merely record development churn, but keep a merge commit when those boundaries will matter during debugging, backports, audits, or selective reverts.

That is the useful distinction. Appearance is not.

A squash merge combines the feature branch's changes into a new single commit on the base branch. The original commits remain on the source branch until it disappears, and copies may persist indefinitely in forks and local repositories, but they are not ancestors of the new commit.

This changes what Git can inspect later. git bisect searches reachable commits, so squashing a pull request with 20 meaningful checkpoints collapses those potential diagnostic stops into one large change.

Most branches contain no such treasure. Commits named “fix lint,” “review changes,” and “actually fix test” describe personal workflow rather than stable units of development.

For an application repository built from short feature branches, squash and merge is usually the right default. Require a precise commit message and keep pull requests narrow.

Libraries are different. Projects that maintain several release branches, publish patch series, verify signed commits, or routinely cherry-pick individual fixes should generally preserve the original sequence with merge commits.

When does commit-level context justify a merge commit?

Keep independently useful commits.

A merge commit earns its place when each feature-branch commit is a coherent, testable unit that maintainers may need to inspect, revert, verify, or backport without taking the rest of the pull request.

Git records a true merge with at least two parents: the previous base tip and the merged branch tip. That structure preserves the branch junction as well as every original commit, as the Git merge documentation specifies.

Use it deliberately.

Good reasons include a curated patch series, a security fix intended for several supported releases, or a refactor split into buildable stages so git bisect can identify exactly where behavior changed.

Authorship can matter too. Squashing replaces several commit objects with one, which means exact object IDs and individual cryptographic signatures no longer form part of the base branch's reachable history, even if GitHub retains contributor details around the pull request.

Do not preserve rubbish ceremonially. A noisy graph does not become an audit trail because every typo correction survived.

Ask one concrete question: could a maintainer reasonably deploy, revert, backport, or investigate this individual commit by itself? If nobody can name such an action, the commit probably does not deserve permanent space on the main branch.

Which Git merge types does GitHub actually create?

GitHub offers three outcomes.

Merge pull request creates a two-parent merge commit, Squash and merge creates one new commit from the combined diff, and Rebase and merge copies the individual commits onto the current base.

The resulting files can match exactly. The histories do not.

  • Merge pull request preserves original commits, hashes, and branch topology.
  • Squash and merge writes one ordinary commit without the feature branch as a parent.
  • Rebase and merge preserves the sequence of changes but gives the copied commits new parents and hashes.

Rebase is often misunderstood. It does not slide existing objects across the graph; it creates replacement commit objects whose parent links point to the updated base.

A hash covers more than the file snapshot. Parent IDs, author and committer information, timestamps, and the commit message all contribute, so changing the parent necessarily changes the identity.

GitHub describes these methods and their repository controls in its pull-request merge methods reference.

Do not equate linear with original. Rebase and merge produces a tidy line, but external automation, signatures, release notes, and other branches referring to old hashes now refer to different objects.

What does each method change in the Git graph?

Parent links decide it.

A regular merge adds a commit with two parents, a squash adds a new commit with only the prior base tip as its parent, and a rebase recreates each feature commit along a new parent chain.

Those links drive later Git behavior. They are not decoration.

With a merge commit, git log --first-parent can show one integration event while the complete graph still exposes every commit from the feature branch. This is useful for release notes and for tracing which pull request introduced a group of changes.

With a squash, the base branch contains only the final unit. Git can revert that unit cleanly when later changes do not overlap, but it cannot selectively revert one of the original feature commits because that object was never merged into the base history.

Rebase occupies the middle ground. It keeps commit-sized steps available to bisect and cherry-pick, yet discards the original hashes and the visible branch junction.

GitHub adds another layer. Its database can associate a squashed commit with a pull request, reviews, checks, approvals, and discussion even though none of that collaboration metadata lives in the Git object graph.

Clone the repository elsewhere, and much of that context stays behind. That is why a hosting platform can display a richer history than Git itself can reconstruct.

How does a Git merge --squash example work locally?

It stages one combined change.

Running git merge --squash feature/login applies the feature branch's net result to the index and working tree, but it neither creates a commit nor records the feature tip as a parent.

Bash
git switch main
git pull --ff-only
git merge --squash feature/login
git diff --cached
git commit -m "Add passwordless login"

Inspect before committing. The staged diff is now the permanent unit you are about to place on main.

The final commit has one parent: the former tip of main. Its snapshot contains the accumulated changes from feature/login, while its ancestry contains no junction leading back to that branch.

The implementation detail matters. Git says --squash prepares the working tree and index as a real merge would, but does not make a commit, move HEAD, or create MERGE_HEAD, in the git merge option reference.

GitHub wraps a comparable graph result in platform behavior. It generates a proposed title and commit message according to repository settings, links the resulting commit to the pull request, and marks the request as merged.

So the command explains the graph, not the entire GitHub experience. Reviews, checks, comments, approvals, and collaboration details remain platform records rather than content stored inside the commit.

How should a team handle reverts and backports after squashing?

Make every pull request atomic.

Because the squashed commit becomes the permanent maintenance unit, its pull request should contain one change that the team can release, explain, revert, and backport without extracting unrelated pieces later.

Reverting is then straightforward. Run git revert <commit>, inspect the inverse patch, and resolve any conflicts introduced by subsequent overlapping changes.

Backports reveal bad boundaries quickly. Cherry-picking one squashed commit is convenient when it contains a focused bug fix, but painful when the same pull request also carries a schema migration, broad refactoring, documentation edits, and incidental cleanup.

Use a short policy:

  1. Keep one operational concern in each pull request.
  2. Rewrite the final commit message around intent, risk, and observable behavior.
  3. Include the pull-request number so GitHub context remains easy to locate.
  4. Split changes before merging when release branches may need only one part.
  5. Preserve commits when a carefully prepared patch series is itself the deliverable.

Do not optimize the graph for screenshots. A perfectly straight history that turns a production regression into an all-day archaeology job has failed its actual purpose.

Branch protection can restrict permitted actions and require approvals or checks, but settings cannot decide whether a commit boundary is meaningful. Humans still have to define the unit they deploy and reverse.

Start there. Then choose the merge policy that keeps that unit intact.

FAQ

Does squash and merge delete the original commits?
No, it does not immediately delete them. The commits remain on the feature branch and may persist in forks, reflogs, or local clones, but they are not ancestors of the squashed commit and may eventually become unreachable after branch deletion.
Can a squashed pull request be reverted?
Yes, revert its resulting commit with git revert <commit>. The operation is cleanest when the pull request was atomic; later overlapping changes can cause conflicts, and Git cannot separately revert an original feature-branch commit that never entered the base history.
Does squash merging preserve every commit author?
No, the base branch receives one new commit with one primary author instead of the original chain of commit objects. Co-author trailers and GitHub's pull-request record can retain attribution, but exact signatures and hashes are not preserved in that branch.
Should a repository allow every merge method?
Usually not. Allowing every method lets contributors choose the permanent history shape case by case, so a team should establish one default and document narrow exceptions for patch series, supported release branches, or backport-heavy work.

Related guides