How Git Rebase Works
What does git rebase do?
Git rebase is the process of moving or combining a sequence of commits to a new base commit. It achieves this by replaying commits from one branch onto a newer base commit. This operation alters the project history by creating entirely new commits and applying them to your specified target base.

When you run a rebase, it helps to look at how Git constructs your history. Instead of recording a join point via a merge commit, the tool takes your feature branch changes. It stacks them sequentially on top of the tip of the destination branch. This leaves you with a straight, linear progression of changes rather than a complex web of intersecting branch lines.
Why git rebase is used
The primary reason for rebasing is to maintain a clean, linear project history. Developers prefer it rather than showing branch joins with merge commits. By avoiding unnecessary merge artifacts, you make code reviews easier and simplify debugging tasks when tracking down regressions.

A linear history allows you and your team to read through the project timeline sequentially. When you use merge commits extensively, the history often fills up with noise. Rebasing keeps feature development isolated and clean before you integrate it into the main production line.
What is rebase vs merge?
While both commands integrate changes from one branch into another, merge preserves history and creates a merge commit when needed, whereas rebase rewrites history to create a linear path (git-scm.com).
| Feature | Git Merge | Git Rebase |
|---|---|---|
| History style | Non-linear, preserves branch structure | Linear, single file succession |
| Commit hashes | Unchanged | Rewritten as new commits |
| Conflict resolution | Resolved once in a merge commit | Resolved commit by commit |
Choose a merge when you need to preserve the exact historical context of a shared feature branch. Choose a rebase when you want to clean up your local changes before pushing them upstream.
What is the golden rule of git rebase?
The golden rule of git rebase is to never rebase a public, shared branch. Doing so can disrupt collaborators who based work on those existing commits. Rebasing rewrites commit history and can generate new commit hashes. Pushing a rebased branch can force collaborators to manually fix their history (git-scm.com).

If you have already shared your branch publicly, stick to merging. Reserve rebasing exclusively for local, unshared commits where rewriting history harms no one else.
When not to use rebase?
You should not use rebase on public branches shared with a team. Avoid it when you lack the time to resolve potential conflicts step by step. Multiple developers might pull from the same feature branch. Rebasing may force everyone else to manually fix their history to sync their local trees (git-scm.com).

Also, avoid interactive rebase when dealing with production hotfixes that require an immediate, auditable trail of exact changes without modification.
Related guides
Frequently asked questions
What is git rebase interactive mode?
Interactive rebase allows developers to make a list of commits. They can squash multiple small commits, reword commit messages, edit commits, or fix bugs. You trigger this mode by passing the interactive flag to the command.
What happens when a rebase conflict occurs?
If changes overlap during a rebase, Git pauses for conflict resolution, requiring developers to resolve integration conflicts manually. After editing the conflicted files, you add them to the staging area and continue the rebase process.
How do I stop a rebase gone wrong?
You can terminate an active rebase operation at any time and return your branch to its original state. Execution of the abort command achieves this. This discards any ongoing rebase actions and restores your working tree.