Summary - Merge and rebase
- Git course
- Intermediate
- Lesson 12/82
- 5 min
Combine both approaches to choose the right merge strategy.
Summary of merge and rebase strategies
Merge and rebase strategies shape the historical readability of your project. git merge preserves branching points for a strictly truthful tree, while git rebase replays commits to maintain a clean and linear timeline. Rebasing on local feature branches and merging into the shared trunk is the most common industry practice.
# Clean up local branch (rebase)
git rebase main
# Integrate into main trunk (merge)
git merge --no-ff ozellikRemember the golden rule: Never rebase a branch shared with others.
Practice Complete rebase and integration flow
Rebase the ozellik branch with git rebase -q main, switch to main, merge with git merge -q ozellik, and print history using git log --format="%s".
Starter code
git init -q
git config user.name "Kaan"
git config user.email "kaan@example.com"
echo "temel" > app.py
git add app.py
git commit -qm "Ilk temel"
git checkout -qb ozellik
echo "eklenti" > eklenti.py
git add eklenti.py
git commit -qm "Ozellik hazirlandi"
git checkout -q main
echo "yama" > yama.txt
git add yama.txt
git commit -qm "Hata yamasi"
git checkout -q ozellik
# rebase yap, main'e gec, merge et ve commit basliklarini yazdirSample solution
git init -q
git config user.name "Kaan"
git config user.email "kaan@example.com"
echo "temel" > app.py
git add app.py
git commit -qm "Ilk temel"
git checkout -qb ozellik
echo "eklenti" > eklenti.py
git add eklenti.py
git commit -qm "Ozellik hazirlandi"
git checkout -q main
echo "yama" > yama.txt
git add yama.txt
git commit -qm "Hata yamasi"
git checkout -q ozellik
git rebase -q main
git checkout -q main
git merge -q ozellik
git log --format="%s"Expected output
Ozellik hazirlandi Hata yamasi Ilk temel
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the most balanced approach in a team to keep a local branch up to date and then integrate it into main?
- Rebase on the main branch and use merge on the local branch
- Delete the entire history and squash everything into a single commit
- Update the local branch with rebase and join the main branch with merge Correct answer
- Reset the shared branches on the remote repository daily with rebase
Explanation: Rebasing locally keeps history clean and linear; merging into main clearly documents the feature integration.
2 Continue rebase after conflict resolution
git rebase ____
git rebase --continue
Explanation: --continue is used to resume the rebase process after conflicts have been resolved.
3 Strategy matching
| Term | Meaning |
|---|---|
Fast-forward |
Advances branch tip without divergence |
Rebase felsefesi |
Provides linear and simple history |
Merge felsefesi |
Preserves all branch points fully |
İki ebeveyn |
Core structure of merge commits |