Skip to content

/compare/git/git-merge-vs-git-rebase

git merge vs git rebase: differences and when to use each

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated 2026-10-20
tool
Git
compares
git merge vs git rebase

git merge combines two branches by creating a merge commit; existing commits stay untouched. git rebase replays your branch's commits on top of another branch, producing a straight line of new commits with new hashes. Merge is safe for shared branches; rebase gives a cleaner history but must not be used on commits others have already pulled.

Same branches, two results

bash
git init -q -b main repo && cd repo
echo base > f && git add f && git commit -qm "base"
git switch -q -c feature && echo feat > g && git add g && git commit -qm "feature work"
git switch -q main && echo fix > h && git add h && git commit -qm "fix on main"
git branch -q feature-copy feature
echo "--- merge:"
git merge -q --no-edit feature && git log --oneline --graph
git reset -q --hard HEAD~1
echo "--- rebase:"
git switch -q feature-copy && git rebase -q main && git log --oneline --graph

Output

--- merge:
*   da13255 Merge branch 'feature'
|\
| * d2e54c4 feature work
* | 249e3b5 fix on main
|/
* 350f8df base
--- rebase:
* 4f9e7f7 feature work
* 249e3b5 fix on main
* 350f8df base

Criterion by criterion

Criteriongit mergegit rebase
History shapebranching, with merge commitslinear
Existing commitsunchangedreplaced by new commits (new hashes)
Conflictsresolved once, in the merge commitresolved commit by commit
Safe on shared branchesyesno: needs a force push and breaks others' clones
Shows when work was integratedyes (merge commit)no
Typical useintegrating feature branches into mainupdating your own branch before a pull request

Rule of thumb

Rebase your local, unpublished work onto the latest main (git pull --rebase, git rebase main) to keep history tidy. Merge when integrating a branch that other people use, or when you want the merge to be visible in history.

Sources