CodeBlanks Logo Icon CodeBlanks

Rebase

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 main

Practice 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

terminal
# Özellik dalına geç

# main üzerine rebase et

Sample solution

terminal
git switch feature/catalog
git rebase main

Expected 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

terminal
# Ana dala geç

# Güncellenmiş özellik dalını birleştir

Sample solution

terminal
git switch main
git merge feature/catalog

Expected 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

Question
git switch feature/search
git rebase ____
Answer
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

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow