Git rebase is a powerful command used to integrate changes from one branch into another by rewriting commit history into a clean, linear sequence.
// Rebase current branch onto another branch
git rebase main
// Switch to feature branch
git checkout feature-branch
// Fetch latest changes from remote
git fetch origin
// Rebase feature branch onto main
git rebase origin/main
The commits from the feature branch are replayed one by one on top of the main branch, resulting in a clean history.
// Start interactive rebase for last 3 commits
git rebase -i HEAD~3