Git Rebase
What
Rebase is a Git command used to integrate changes from one branch into another by moving or “replaying” a sequence of commits on top of a new base commit. While git merge combines two histories using a merge commit, git rebase rewrites history to create a completely linear sequence.
How
Consider a scenario where a feature branch has diverged from your main branch:
# Diverged branches before rebasing:
A - B - C main
\
D - E feature_branch
If you rebase feature_branch onto main, Git will lift commits D and E, find the new base commit C at the tip of main, and replay those commits one by one on top of it.
# After rebasing 'feature_branch' onto 'main':
A - B - C main
\
D' - E' feature_branch
Note: The replayed commits D' and E' contain the same content modifications as D and E, but they will have new parent pointers and completely unique commit hashes.
Why
Merging is excellent for preserving the exact historical sequence of commits, but in large teams, hundreds of branch merges can create a messy web of parallel paths and automatic “Merge branch…” commits. Rebasing eliminates these extra merge commits and maintains a perfectly clean, linear timeline, making history much easier to read, parse, and troubleshoot.
Summary
Git rebase integrates changes by replaying a branch’s commits on top of another branch’s tip, preserving a clean, linear history without creating automatic merge commits.