Overview
Suppose a feature branch is created from main. Work then continues independently:
- The feature branch receives a commit for feature functionality.
- Main receives a separate commit for a new interface update.
The feature branch now lacks the newer main commit.
Switch to the feature branch:
git checkout feature
Rebase it onto main:
git rebase main
Git performs the operation conceptually in four stages:
- Identify the most recent commit shared by feature and main.
- Temporarily set aside the feature commits that came after that common point.
- Apply the newer main commits to the feature branch's base.
- Reapply the saved feature commits one by one on top of the updated base.
The resulting feature branch contains the latest main changes followed by the feature work. The history reads as though the feature work began from the newer main state.