Git Rebase vs Merge and How to Choose for Your Team
Your feature branch is three days old, main has moved on by 40 commits, and the pull request page says "This branch is out of date".

Your feature branch is three days old, main has moved on by 40 commits, and the pull request page says "This branch is out of date". You can click "Update with merge commit" or "Update with rebase", and half your team swears by one while the other half insists the other ruins history.
The git rebase vs merge argument is older than most of the codebases it happens in, and it rarely needs to be a fight. Both commands combine work from two branches. They just record that work differently, and each has situations where it is clearly the better tool. Here is how they differ, where each one bites, and a simple team policy that works for most web projects.
What merge does
A merge takes two branches and joins them with a new merge commit. That commit has two parents: the tip of your branch and the tip of the branch you merged in. Nothing that already exists is changed.
Running git merge main while on your feature branch brings the latest main into your work. The history now shows a fork and a join, exactly as it happened.
- Strength: it is non destructive. Existing commits keep their hashes, so anyone else who has your branch is unaffected.
- Strength: conflicts are resolved once, in one commit.
- Weakness: busy repositories fill up with "Merge branch main into feature" commits, which makes the log harder to read.
What rebase does
A rebase takes the commits on your branch and replays them, one by one, on top of another branch. Running git rebase main on your feature branch lifts your commits off the old starting point and reapplies them after the latest commit on main.
The result looks as if you started your work today. The history is a straight line with no merge commits.
- Strength: a clean, linear log that is easy to read and easy to search.
- Strength: tools like git bisect work more smoothly on a linear history, because every commit sits on one path.
- Weakness: every replayed commit gets a new hash. If someone else already pulled your branch, their copy no longer matches yours.
- Weakness: conflicts can appear commit by commit. A branch of 12 commits that touch the same file can mean resolving similar conflicts several times.
Git rebase vs merge side by side
| Question | Merge | Rebase |
|---|---|---|
| Changes existing commits? | No | Yes, new hashes |
| History shape | Branches and joins | Straight line |
| Safe on shared branches? | Yes | No, unless everyone agrees |
| Conflict handling | Once, in the merge commit | Per commit, possibly repeated |
| Needs a force push afterwards? | No | Yes, if the branch was pushed |
| Best for | Integrating finished work into main | Tidying your own local branch |
The one rule that prevents most rebase disasters
Never rebase commits that other people have based work on. In practice that means do not rebase main, develop or any branch two people push to.
The failure looks like this. You rebase a shared branch and force push it. A teammate pulls, git sees two different histories with similar changes, and creates a merge that duplicates every commit. Untangling that on a Friday afternoon can take an hour, and it happens often enough that many teams ban rebase outright.
If you must force push your own feature branch after a rebase, use the force with lease option rather than a plain force push. It refuses to overwrite the remote if someone pushed new commits since you last fetched, which catches the most common accident.
Why "always rebase for a clean history" is overrated
A popular piece of advice is that a perfectly linear history is always better, so everyone should rebase everything. I disagree, at least for most product teams.
A linear history is pleasant to read, but it is also a slightly fictional one. It hides when work actually happened in parallel, which is sometimes exactly what you need to know when tracking down an integration bug. More importantly, the pursuit of a tidy log pushes less experienced developers into interactive rebases and force pushes they do not fully understand, and lost work is a far bigger cost than a few merge commits.
The better goal is a readable main branch, not a perfect one. Squash merging pull requests gets you most of the benefit with none of the risk: each feature lands on main as a single commit with a clear message, and nobody has to rewrite a shared branch.
A simple team policy that works
After trying several approaches across front-end and API teams, this is the policy I recommend for most web projects:
- Locally, rebase freely. Before you open a pull request, use git rebase -i to squash "fix typo" and "try again" commits into a few meaningful ones.
- To update a feature branch only you work on, rebase onto main. Set git config pull.rebase true so pulls on your own branches do not create noise commits.
- To update a branch others share, merge main into it. No rewriting.
- To land work on main, use squash merge or a regular merge through the pull request, never a local rebase and push.
- Protect main in your hosting settings so force pushes are blocked.
This gives each developer a tidy branch, keeps main readable and makes the dangerous operation impossible on the branches that matter.
How to recover when a rebase goes wrong
Rebases feel scary because commits seem to disappear. They almost never do. Git keeps a record of where every branch pointed in the reflog, usually for 90 days.
- If a rebase is mid way and conflicts look wrong, abort it with the abort option and you are back where you started.
- If you finished a rebase and regret it, run git reflog, find the entry from before the rebase, and reset your branch to that commit.
- If you have uncommitted changes, stash them first. Our guide to using git stash without losing work covers the safe way.
Knowing the reflog exists makes rebase far less stressful, and it is the first thing I show anyone new to the command. For more workflow habits like this, see our dev tools articles.
Frequently asked questions
Is it better to rebase or merge in git?
Neither is better in every case. Rebase is ideal for tidying and updating your own unshared branch, while merge is safer for shared branches and for integrating finished work. Most teams use both, with clear rules for each.
Why is git rebase considered dangerous?
Rebase rewrites commits and gives them new hashes. If other people already have those commits, their history no longer matches yours, which leads to duplicate commits and confusing conflicts. Only rebase work that nobody else has pulled.
Does squash merge replace the need for rebase?
Largely, for keeping main clean. A squash merge turns a whole pull request into one commit, so messy branch history never reaches main. You may still rebase locally to keep a long running branch up to date and easy to review.
More in Dev Tools
Dev Tools
How to Use the DevTools Coverage Tab to Find Dead CSS
A stylesheet on a project I inherited was 184KB minified, one file for the whole site.
Dev Tools
How to Use curl Timing to Find Why an API Request Is Slow
"The API is slow" is one of the least useful bug reports, and also one of the most common.
Dev Tools
Console Methods Beyond console.log That Save Debugging Time
You add console.log to a loop, refresh, and the panel fills with 400 identical lines of "[object Object]" and "here".