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
| Command | Description |
|---|---|
| pick | Keep commit |
| reword | Change message |
| edit | Modify commit |
| squash | Combine with previous |
| drop | Remove commit |
Rebase vs Merge
| Feature | Rebase | Merge |
|---|---|---|
| History | Linear | Branching |
| Commit order | Changed | Preserved |
| Conflicts | May occur | May occur |
| Use case | Clean history | Preserve 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
- Rebase onto main
- Use interactive rebase
- Squash commits
- 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.