Rebase
- Git course
- Intermediate
- Lesson 80/82
- 6 min
Set up a linear history by rebasing a feature branch.
Linear history with rebase
Rebase reapplies the commits of one branch on top of the current tip of another branch. This can make the history appear more linear without creating a merge commit. To move a feature branch onto the updated main, run git rebase main while on the feature branch.
git switch feature/search
git rebase mainPractice Switch to the correct branch before rebasing
Switch to the feature/catalog branch and rebase it onto main. Write the two commands in order.
Starter code
# Özellik dalına geç
# main üzerine rebase etSample solution
git switch feature/catalog
git rebase mainExpected output
Switched to branch 'feature/catalog'. Successfully rebased and updated refs/heads/feature/catalog.
Practice Merge the rebased branch into main
The rebase of feature/catalog is complete. Switch to the main branch and merge the updated feature branch. Write the two commands in the correct order.
Starter code
# Ana dala geç
# Güncellenmiş özellik dalını birleştirSample solution
git switch main
git merge feature/catalogExpected output
Switched to branch 'main'. Feature branch merged.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which operation reapplies feature branch commits on top of the updated main branch?
- git reset main
- git cherry-pick main
- git revert main
- git rebase main Correct answer
Explanation: While on the feature branch, git rebase main reapplies its commits on top of the current tip of main.
2 Update the feature branch
git switch feature/search
git rebase ____
git switch feature/search
git rebase main
Explanation: The rebase target is main, the branch onto which the feature branch will be replayed.
3 Rebase concepts
| Term | Meaning |
|---|---|
Rebase |
Reapplies commits |
Hedef dal |
Branch receiving the commits |
Doğrusal geçmiş |
A straighter commit history |
Özellik dalı |
Contains development commits |