Resolve conflicts
- Git course
- Intermediate
- Lesson 77/82
- 5 min
Resolve a conflict that arises during rebase.
Conflict during rebase
A conflict may occur when rebasing a feature branch onto an updated main branch if different changes affect the same lines. Git pauses the operation and waits for you to decide which changes to keep. After editing and saving the conflicted file, you can stage the resolution and continue the rebase.
git rebase main
# Resolve the conflict
git add index.html
git rebase --continueSteps to resolve a conflict
In a conflicted file, the markers <<<<<<<, =======, and >>>>>>> show which sections conflict. Keep the desired content, remove these markers, and save the file. Finally, stage the file and continue the rebase.
git status
git add index.html
git rebase --continuePractice Complete the rebase conflict resolution
Assume that you have resolved a conflict on the feature/cart branch. Stage the cart.js file and continue the rebase. Write the commands in the correct order.
Starter code
# Çözülmüş dosyayı sahnele
# Rebase işlemine devam etSample solution
git add cart.js
git rebase --continueExpected output
cart.js staged. Rebase completed successfully.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command continues the operation after resolving a conflict during rebase?
- git reset --hard
- git branch -d
- git merge --abort
- git rebase --continue Correct answer
Explanation: After resolving the conflict and staging the file, git rebase --continue resumes the operation.
2 Continue the rebase after resolving a conflict
git add index.html
git rebase ____
git add index.html
git rebase --continue
Explanation: After the conflict resolution is staged, --continue resumes the rebase process.
3 Rebase conflict operations
| Term | Meaning |
|---|---|
git status |
Shows conflicted files |
<<<<<<< |
Starts the current change section |
git add |
Stages the resolved file |
--continue |
Continues the rebase |