Hello, I'm Maneshwar. I’m building LiveReview, a private AI code review tool that runs on your LLM key (OpenAI, Gemini, etc.) with highly competitive pricing -- built for small teams. Do check it out and give it a try!
Rebasing is one of Git’s most powerful but also most misunderstood commands.
It helps you keep a clean, linear commit history, but it also introduces conflicts that can be tricky to resolve.
In this post, we’ll break down what rebasing is, when to use it, how conflicts occur, and how to deal with them.
What is Rebase?
git rebase
is a command that takes commits from one branch and reapplies them on top of another.
Instead of merging (which creates a new commit joining two branches), rebasing replays your commits one by one on top of the target branch.
Example:
# Rebasing your feature branch on top of main
git checkout feature
git rebase main
This rewrites commit history so that it looks like you started your work from the latest main
.
Rebase vs Merge
- Merge: Preserves history but introduces merge commits.
- Rebase: Creates a linear history, easier to read, but rewrites commits.
👉 Use merge when you want to keep a record of how branches diverged.
👉 Use rebase when you want a clean, straight commit history.
Aborting a Rebase
If something goes wrong during a rebase (for example, conflicts you don’t want to deal with), you can stop it:
git rebase --abort
This restores your branch to the state before the rebase started.
Preventing Automatic Rebase by Default
Sometimes Git suggests rebasing when you git pull
.
If you prefer merges by default, disable auto-rebase globally:
git config --global pull.rebase false
You can also enable it (if you want linear history always):
git config --global pull.rebase true
When Do Rebase Conflicts Occur?
Conflicts occur during rebase for the same reason they occur in merges:
- Two branches change the same lines in a file.
- One branch deletes a file while another modifies it.
- File renames combined with edits.
Example scenario:
- Branch
main
changes functionfoo()
. - Your
feature
branch also changes the samefoo()
. - During
git rebase main
, Git cannot decide which change to keep → conflict.
How to Solve Rebase Conflicts
- Check conflict files
git status
You’ll see files marked as both modified.
- Open the files and look for conflict markers:
<<<<<<< HEAD
Code from main
=======
Code from feature branch
>>>>>>> feature
Manually edit to keep the correct version (sometimes both).
Mark as resolved
git add <file>
- Continue rebase
git rebase --continue
- If it gets messy →
git rebase --abort
Best Practices for Rebasing
- Try not to rebase public/shared branches (rewriting history confuses collaborators).
- Rebase your feature branch on main before merging → keeps history clean.
Summary
-
git rebase
makes history linear,git merge
keeps history intact. - Use
--abort
to stop a rebase if things go wrong. - Control default rebase behavior with
git config pull.rebase
. - Conflicts happen when the same file/line is modified in multiple branches.
- Solve conflicts by editing files, staging them, and running
git rebase --continue
.
Done right, rebase keeps your Git history tidy and professional, but remember to use it wisely.
LiveReview helps you get great feedback on your PR/MR in a few minutes.
Saves hours on every PR by giving fast, automated first-pass reviews.
If you're tired of waiting for your peer to review your code or are not confident that they'll provide valid feedback, here's LiveReview for you.
Top comments (0)