# Git rebase vs merge

> Merge joins histories with a merge commit; rebase replays your commits on another tip for a linear story.

Source: https://fullbytedeveloper.com/blog/git-rebase-vs-merge
Published here: 2026-12-03, updated 2026-12-03

Git integrates branch work with merge or rebase [1][2]. Merge joins tips with a merge commit; rebase replays your commits onto another tip so history looks linear [1]. The final tree can match; the story in `git log --graph` will not. Pair with [What is Git?](/blog/what-is-git).

## Quick start: read the graph

```bash
git log --oneline --graph -10
```

Forks with join nodes usually mean merges. A single column often means rebase or fast-forward only. The graph is the story; the tree at HEAD is the code.

## Compare merge and rebase on this host

Observed on this host (git 2.43.0, ephemeral repos under `/tmp`, 2026-12-03). Diverged branches before rebase:

```text
* 15d5d30 feature edit
| * e307b90 main moves
|/  
* 49bc315 init
```

After `git checkout feature && git rebase main`:

```text
* 0221b3a feature edit
* e307b90 main moves
* 49bc315 init
```

After an explicit merge on a similar two-branch demo:

```text
*   c05a6de Merge branch feature
|\  
| * 08f8db2 feat
* | c63e3df mainline
|/  
* 49bc315 init
```

Rebase moved the feature commit after main's tip with a new commit hash. Merge recorded both tips with a merge commit preserving the fork [1][2].

Reproduce the rebase demo:

```bash
rm -rf /tmp/git_rebase_clean && mkdir /tmp/git_rebase_clean && cd /tmp/git_rebase_clean
git init -q && git config user.email 'demo@example.com' && git config user.name 'Demo'
echo base > README && git add README && git commit -qm init
git branch -M main
git checkout -qb feature
echo feature-only > feat.txt && git add feat.txt && git commit -qm 'feature edit'
git checkout -q main
echo main-only > main.txt && git add main.txt && git commit -qm 'main moves'
git log --oneline --graph --all
git checkout -q feature && git rebase main
git log --oneline --graph --all
```

## Draw the two histories

<figure>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 280" role="img" aria-label="Merge keeps a join commit; rebase replays onto a linear tip">
  <defs>
    <marker id="rebaseMergeArrow" markerWidth="10" markerHeight="10" refX="8" refY="3" orient="auto">
      <path d="M0,0 L8,3 L0,6 Z" fill="#14b8a6"/>
    </marker>
  </defs>
  <rect x="0" y="0" width="720" height="280" rx="12" fill="#0b1f3a"/>
  <text x="24" y="36" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="16" font-weight="700">merge vs rebase</text>
  <rect x="24" y="56" width="330" height="190" rx="8" fill="#123052" stroke="#f59e0b" stroke-width="2"/>
  <text x="40" y="88" fill="#f59e0b" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">Merge (keeps fork)</text>
  <text x="40" y="120" fill="#f8fafc" font-family="ui-monospace, monospace" font-size="14">A - B - - - M</text>
  <text x="40" y="148" fill="#f8fafc" font-family="ui-monospace, monospace" font-size="14">     \      /</text>
  <text x="40" y="176" fill="#f8fafc" font-family="ui-monospace, monospace" font-size="14">      C ---/</text>
  <text x="40" y="216" fill="#cbd5e1" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">M has two parents [2]</text>
  <rect x="374" y="56" width="322" height="190" rx="8" fill="#123052" stroke="#14b8a6" stroke-width="2"/>
  <text x="390" y="88" fill="#14b8a6" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">Rebase (linear story)</text>
  <text x="390" y="128" fill="#f8fafc" font-family="ui-monospace, monospace" font-size="14">A - B - C'</text>
  <path d="M390 160 H520" stroke="#14b8a6" stroke-width="3" fill="none" marker-end="url(#rebaseMergeArrow)"/>
  <text x="390" y="196" fill="#cbd5e1" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">C' new SHA, same patch idea</text>
  <text x="390" y="224" fill="#f59e0b" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">do not rebase public commits [1]</text>
</svg>
</figure>

*Same end tree is possible; the graph and commit IDs tell different stories.*

## Commands for the safe local sequence

```bash
git checkout experiment
git rebase main
git checkout main
git merge experiment
```

That sequence rebases `experiment` onto `main`, then fast-forwards `main` when the tip is a descendant [1]. If `main` moved again, repeat rebase before merge.

`git pull --rebase` applies the same idea when updating your branch from upstream instead of merging upstream into your unpushed work.

## Obey the public-history rule

Pro Git in one line: do not rebase commits that exist outside your repository and that people may have based work on [1]. Rewriting shared commits forces teammates into messy re-merges and duplicate-looking history [1].

Safe habit: rebase only local unpublished work; once pushed and shared, prefer merge (or a coordinated force-push policy) [1]. Branch protection can block force-pushes ([GitHub branch protection settings](/blog/github-branch-protection-settings)) [4].

Force-push after rebase is normal on your own feature branch nobody else fetched. Force-push on `main` is an incident unless the team planned it.

## Resolve conflicts in either path

Both merge and rebase stop on conflicts. Merge leaves you on a merge commit in progress. Rebase leaves you mid-replay with `git rebase --continue`. In both cases you edit files, `git add`, then continue [1][2].

Rebase conflicts can appear once per replayed commit; merge conflict often appears once at the join. Either can be tedious on long branches. Use different files on teaching demos if you only want to show graph shape without conflict noise.

## Pick for the audience of the log

History-as-record camps keep merges. History-as-story camps rebase private work before publishing [1]. Many teams do both: rebase locally for a clean PR, merge on the shared default branch so the integration is explicit [1].

Squash merge on GitHub is a third shape: many commits become one on `main`. That erases per-commit story on the default branch while keeping review granularity in the PR.

## When merge is the better default

Long-lived shared branches, release branches, or anything multiple people pull should merge unless everyone agrees on rebase rules. Hotfix branches merging back to `main` and `develop` often use explicit merge commits for audit trails [2].

## Fast-forward merge versus explicit merge

When `main` has not moved since you branched, `git merge feature` may fast-forward: no merge commit, just move the pointer. When both tips moved, Git creates a merge commit unless you rebase first [2].

```bash
git checkout main
git merge --ff-only feature
```

`--ff-only` refuses a merge commit. CI uses it to detect unexpected divergence.

## Interactive rebase for cleanup

`git rebase -i main` lets you squash, reword, or drop commits before publishing. That is still rewriting unpublished history. Once commits are on a shared remote, interactive rebase needs the same coordination as any force-push [1].

## Reflog as a safety net

```bash
git reflog -5
```

Reflog still lists pre-rebase tips for a while so you can reset. Entries expire after gc; do not treat them as backup policy [1].

## Bisect and archaeology

Merge commits preserve which integration introduced a bug. Pure linear rebase can make `git bisect` walk a single line but loses the moment two branches met. Neither is universally better; pick history shape to match how your team audits releases [1][2].

## Cherry-pick as a third integrator

`cherry-pick` copies a single commit's patch onto another branch without merging the whole branch. Useful for backports. It creates new SHAs like rebase does [1]. Document cherry-picks in release notes so reviewers know the commit on `main` is not the same object as the one on `develop`.

## Remote-tracking branches

`origin/main` moves when you fetch. `git rebase origin/main` while on a local branch updates your commits against the server tip without merging into `main` locally. Confusion between local `main` and `origin/main` causes many accidental merge commits; `git status -sb` shows both divergences.

Tags on commits survive rebase only when you move them; otherwise tags still point at old SHAs. Release engineers sometimes tag after merge specifically to avoid chasing rewritten tips [1].

## Merge messages and PR titles

Merge commits carry default messages Git generates from branch names. Editing them at merge time helps future `git log` readers. Rebased histories put commit subjects from the topic branch directly on `main`; subject quality matters before rebase [1][2].

## Common mistakes

Rebasing `main` after others based work on it. That is the Pro Git stop rule [1].

Treating rebase as a way to avoid conflicts. It moves when conflicts happen, not whether.

Thinking merge and rebase always produce identical trees without checking. They can differ if conflict resolutions differ per step.

Force-pushing a shared feature branch because "rebase is cleaner" without telling collaborators. They need `git fetch` and reset or rebase onto your new tips.

Using `git pull` default merge on a linear-preferred team without documenting `pull.rebase`.

Treating squash merge and rebase as the same. Squash combines into one commit at integrate time; rebase rewrites each commit's parent.

## Related reading

Snapshot model: [What is Git?](/blog/what-is-git) [3]. Remote policy: [GitHub branch protection settings](/blog/github-branch-protection-settings) [4].

You now have a Pro Git sourced rebase versus merge choice with graphs measured on this host. Prefer boring team rules over clever one-off history surgery during an incident.

Write the house rule in one line somewhere reviewers will see it: rebase private topic branches, merge (or squash) on the shared default branch, never rewrite published commits without a coordinated plan [1]. That single sentence prevents most Friday-night force-push stories. Put the same line in onboarding so new hires do not learn history policy from an outage.

Browse the [Dev tools topic](https://fullbytedeveloper.com/blog/topic/dev-tools).

Send this to the friend who force-pushes rewritten main and wonders why history vanished.

Image: Split diagram on a dark grid. Left: branching teal and tan commit discs that join in interlocking rings. Right: a single vertical stack of teal and tan discs under a teal bar, with side arrows marking the replay.
https://fullbytedeveloper.com/media/git-rebase-vs-merge/git-rebase-vs-merge-venice.webp
Merge keeps the fork and join; rebase replays commits into one linear column.

## Sources

1. [Pro Git: Git Branching - Rebasing, accessed 2026-12-03](https://git-scm.com/book/en/v2/Git-Branching-Rebasing)
2. [Pro Git: Basic Branching and Merging](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging)
3. [Full Byte Developer: What is Git?](https://fullbytedeveloper.com/blog/what-is-git)
4. [Full Byte Developer: GitHub branch protection settings](https://fullbytedeveloper.com/blog/github-branch-protection-settings)
