Merge vs RebaseBeginner
1Question 1 of 1
bashWhat is the difference between Git Merge and Git Rebase?
Explanation & Concept
Both commands integrate changes from one branch into another:
• `git merge`: Preserves the exact historical timeline and creates a new 3-way 'merge commit'. It is non-destructive, safe for shared public branches, but can create complex branch history graphs. • `git rebase`: Re-applies commits from the feature branch on top of the base branch, creating a completely linear project history. **Never rebase commits that have been pushed to a shared public branch**.
Code Example
bash
# 1. Rebase feature branch on top of main for linear history
git checkout feature-branch
git rebase main
# If conflicts occur, resolve and continue:
# git add <resolved-files>
# git rebase --continue
# 2. Fast-forward merge into main
git checkout main
git merge feature-branchHow It Works & Key Takeaways
Rebasing keeps Git commit history clean and easy to navigate with `git bisect`, while merge preserves the true chronological order of commits.
Mock Test · 1 Questions · Optional
Ready for Stashing?
Take a quick test to evaluate yourself, or move straight to the next module.
Beginner3 questions