Git Rebase
Git rebase
The git rebase command is used to move or combine commits from one branch onto another. This rewrites commit history.
git checkout <feature-branch>
git rebase <main-branch>
Applies commits from
Interactive rebase:
git rebase -i <commit-hash>
Allows you to edit, squash, or reorder commits.
Abort a rebase:
git rebase --abort
Stops the rebase and restores the branch to its original state.
Why rebase?
Pros: Creates a clean, linear commit history. Cons: Can cause conflicts, especially with shared branches. Avoid rebasing public branches.