🏠 Homepage 🏠 Syllabus of Day 2 ⬅️ Previous: 🔀 Merging the PR into Main
A merge conflict occurs when Git cannot automatically combine changes from different branches because the same lines in a file have been changed in both branches. This usually happens during merging or rebasing.
⚠️ Merge conflicts can occur whether you merge changes using a GitHub Pull Request,
git pull
, orgit fetch
+git merge
. The steps to resolve conflicts are the same in all cases.
git merge branch-name
If there are conflicts, Git will pause the merge and mark the conflicted files.
git status
Conflicted files will be listed as “both modified”.
<<<<<<< HEAD
Your changes
=======
Incoming changes
>>>>>>> branch-name
git add filename.txt
git commit
(If you were in the middle of a merge, this will finish it.)
git checkout main
git pull origin main
git merge feature-branch
# Resolve conflicts in your editor
git add conflicted-file.txt
git commit
💡 Other Tips
git status
to ensure all conflicts are resolved.Step | Command/Action |
---|---|
Start merge | git merge branch-name |
Check conflicts | git status |
Edit files | Resolve conflict markers in editor |
Stage resolved files | git add filename.txt |
Complete merge | git commit |
Tip:
Take your time resolving conflicts and test your code after merging to ensure everything works
➡️Up Next: 📋Summary & Cheatsheet