What is Git rebase and when is it better to use it instead of merge?

Published on 2026-10-20 by frfrand

Git Rebase explained with examples: linear history, identifier changes, differences with merge, and how to avoid rewriting shared branches.

What is Git rebase and when is it better to use it instead of merge?

Short answer: git rebase moves or replays a series of commits onto another starting point in history. It leaves a more linear history than a merge, but creates new commits with different identifiers, so it is best used on your own branches and not on branches that other people have already downloaded.

It is often used to update a working branch and maintain a more linear sequence, but there is an important warning: it can change commit identifiers.

It does not make your code better by itself. It is a tool for organizing repository history.

The recipe example

Imagine you wrote three steps to prepare a cake based on an old recipe. Meanwhile, someone changed the base recipe. You can try to apply your three steps to the updated version.

That is similar to rebase: Git takes commits from your branch and reapplies them from another base. The result can have the same functional effect, but the generated history is not identical to the previous one.

How does it differ from merge?

A merge brings histories together and, in a non-trivial combination, normally creates an integration commit that preserves the relationship between branches.

A rebase reapplies commits, generally giving a more linear visual history. It can be convenient for reviewing, but it also makes certain commits be represented as new objects.

No strategy is universally superior. Some teams value preserving the exact history of integrations, while others prefer a simpler line to read.

Common example

You are working on a branch feature/reservas and want to incorporate recent changes from main:

git fetch origin
git switch feature/reservas
git rebase origin/main

If there are no conflicts, Git continues. If they appear, you must resolve them and follow the indicated procedure, for example git rebase --continue.

Before using these commands, verify that you are on the correct branch and that your local work is saved.

Why do hashes change?

A commit references its parents. If you change that starting point, part of the data that identifies it changes. Although the code looks the same, it is no longer the same commit.

That is why it is dangerous to rebase a public branch that other people are already using and then force its publication without coordinating. You could force them to reconcile divergent histories or cause confusion with duplicate commits.

If you have to push your own branch after a rebase, prefer git push --force-with-lease over --force: it rejects the push if someone has uploaded something new that you haven't seen yet.

What is interactive rebase?

Git allows you to reorganize or combine local commits through an interactive mode. For example, if you made five "adjustment" commits, you could prepare a more readable history before opening a pull request.

That can be useful before sharing the work. But it should not be used as an excuse to erase evidence of important decisions or rewrite others' changes.

Does rebase resolve conflicts automatically?

No. It can stop when two changes conflict. The difference is that, when replaying several commits, you might have to resolve problems at different steps.

In a situation you don't understand, git rebase --abort can cancel the ongoing operation and return to the previous state of that rebase. It is preferable to stop and review than to introduce uncertain changes.

When is it convenient to use it?

If you work on your own branch, you want to bring changes from the main branch, and your team has a linear history policy, it can be a good option.

If the branch is shared, the team values the real history of integrations or is not comfortable with rewrites, a merge may be more appropriate.

And in ArduMaker?

An application that you deploy from Git in ArduMaker does not need rebase to work. It does need a coherent repository, a clear version reference, and tests before deployment. Rebase is a development flow decision, not an infrastructure requirement.

A practical detail: if you rebase the branch that deploys and force push it, the ArduMaker deploy does not get stuck. If it cannot advance in a straight line, it leaves the server copy equal to the GitHub branch, and what was only in that copy is discarded.

The conclusion: rebase is used to reapply changes from a different base. Use it when you understand how it affects history and avoid rewriting branches that other people have already downloaded without coordinating.

Frequently asked questions

Does rebase delete commits? It replaces the branch commits with new copies. The originals remain for a while in the reflog (git reflog), from where they can be recovered if something went wrong.

What is the difference between --force and --force-with-lease? --force overwrites the remote branch without checking; --force-with-lease only overwrites it if it is still as you last saw it, so you don't accidentally delete someone else's work.

Merge or rebase? Rebase to clean up your own branch before sharing it; merge to integrate shared branches or when the team wants to preserve the real history of integrations.

Sources: Official Git rebase · Rebase in Pro Git.

What is Git rebase and when is it better to use it instead of merge?
  • Git
  • rebase
  • ramas

Keep reading

All articles · VPS plans