</>
Skip to content
Git lessons (20/44)

Git — Rebase

What is Rebase?

Rebase moves or combines a sequence of commits to a new base commit.

Basic Rebase

# On feature branch
git rebase main

Interactive Rebase

# Rebase last 3 commits
git rebase -i HEAD~3

Rebase Commands

CommandDescription
pickKeep commit
rewordChange message
editModify commit
squashCombine with previous
dropRemove commit

Rebase vs Merge

FeatureRebaseMerge
HistoryLinearBranching
Commit orderChangedPreserved
ConflictsMay occurMay occur
Use caseClean historyPreserve history

After Rebase

# Force push (required)
git push --force-with-lease origin feature-branch

Abort Rebase

git rebase --abort

Continue Rebase

# After resolving conflicts
git add .
git rebase --continue

Mini Practice

  1. Rebase onto main
  2. Use interactive rebase
  3. Squash commits
  4. Resolve rebase conflicts

Up Next

Continue with Stash — stashing changes.

Related Topics

Frequently Asked Questions about Rebase

What is Rebase in Git?

Rebase is a fundamental concept in Git. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Rebase?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Rebase.

Why is Rebase important in Git?

Rebase is essential for Git development. Understanding this concept will help you write better code and solve real-world problems more effectively.