🌿 Branching
How to rebase a branch in Git
Reapply commits on top of another branch for a linear history.
Rebase current branch onto main
git rebase mainReplays all commits from the current branch on top of main. Creates a linear history.
When to use: Before merging a feature branch to bring it up to date with main.
Interactive rebase (last N commits)
git rebase -i HEAD~3Opens an editor to rewrite the last 3 commits. You can squash, reword, drop or reorder.
When to use: Cleaning up commit history before a pull request.
Abort a rebase in progress
git rebase --abortCancels the rebase and returns to the original state.
Continue after resolving conflicts
git rebase --continueAfter resolving conflicts and staging the fixes, continue the rebase.