Skip to content

Rebase instead of merge confusion

Quick summary

You rebased when you meant to merge (or the reverse), producing a linear history instead of a merge commit — teammates may see rewritten commits.

Why this happens

  • You ran git rebase instead of git merge by habit or typo, rewriting local commits on top of the target branch

  • A team convention requires merge commits but you used rebase, or the convention requires rebase but you merged

  • You rebased commits that were already pushed and shared, causing history divergence for teammates

Minimal example

✗ Broken code
git rebase main  # intended git merge main — history rewritten
git push --force  # teammates see rewritten commits
✓ Fixed code
git rebase --abort  # if still in progress
git reset --hard ORIG_HEAD  # undo completed rebase
git merge main  # create merge commit as originally intended

ORIG_HEAD points to the state before the rebase started, allowing you to undo the rebase and perform a merge instead, preserving the original commit hashes.

How to diagnose

  • Run git log --oneline --graph to see whether the history is linear (rebase) or has a merge commit (merge)

  • Check git reflog to find the pre-rebase state if you need to undo the rebase and switch to a merge

  • Compare local and remote with git log origin/branch..HEAD to see if commits were rewritten and need force push

How to fix

  • Undo the rebase with git rebase --abort if still in progress, or git reset --hard ORIG_HEAD to restore pre-rebase state

  • If you merged but should have rebased, reset to pre-merge with git reset --hard HEAD~1 then git rebase origin/branch

  • If already pushed after rebase, communicate with teammates and coordinate a force-push-with-lease to sync history

How to prevent

  • Agree on a team convention (rebase vs merge) and document it in CONTRIBUTING.md to avoid inconsistent history

  • Never rebase commits that have been pushed to shared branches — only rebase local unpushed commits

Related Resources

Related Glossary

Related Lessons

← Back to language