📝 Git & GitHub

Git Conflicts: Step-by-Step Breakdown ⚔️

0
Author
04e5cc8b-58ac-4bdc-bdee-661bbb
📅
Published
06.05.2026
⏱️
Reading time
4 min
👁️
Views
45
🌱
Level
Beginner

A merge conflict is a situation where Git cannot automatically combine changes from two branches because both developers modified the same location in the same file.

What Is a Merge Conflict

Why Conflicts Happen

main:    ... line A ...  →  ... line A edited by Ivan ...
feature: ... line A ...  →  ... line A edited by Maria ...

Git doesn’t know whose version of line A to keep — yours or main’s. It stops and asks a human to decide.

Conflicts are normal. Every developer runs into them. It’s not a Git error and it’s nobody’s fault — two people simply worked on the same part of the code at the same time.

When Conflicts Occur

  • During git merge (merging branches)
  • During git pull (if the remote branch changed)
  • When updating your branch from main
  • When creating a PR (GitHub will show a warning)

What a Conflict Looks Like

After a failed merge, Git marks the conflicting spots directly in the file:

<<<<<<< HEAD (or your branch name)
Your changes
=======
Changes from the other branch (main)
>>>>>>> main

Breaking down the markers:

<<<<<<< HEAD
| Anna Morozova | @anna-morozova | Moscow |    ← YOUR version
=======
| Sergey Pavlov | @sergey-pavlov | St. Pete |    ← version from main
>>>>>>> main

Everything between <<<<<<< and ======= — your changes.
Everything between ======= and >>>>>>> — changes from the other branch.

Ways to Resolve

Resolving in GitHub Desktop

GitHub Desktop detects the conflict automatically and shows a warning.

Step 1: See the warning

GitHub Desktop shows:

⚠️ “There are merge conflicts” + list of conflicting files

Step 2: Open the file in an editor

Click Open in Editor or open the file manually.

Step 3: Find the markers and resolve

You need to:
1. Choose the content you want (your version, theirs, or both)
2. Delete ALL three markers: <<<<<<<, =======, >>>>>>>
3. Save the file

Step 4: Commit

Return to GitHub Desktop — the conflicting file now appears in Changes.
Write a commit message: fix: resolve conflict in contributors.md
Click Commit.

Resolving in VS Code

VS Code shows conflicts with action buttons right in the editor:

  • Accept Current Change — keep your version
  • Accept Incoming Change — keep the version from the other branch
  • Accept Both Changes — keep both versions (one after the other)
  • Compare Changes — show differences side by side

Click the button you need — VS Code removes the markers automatically.

Three Ways to Resolve

1. Keep your version

<<<<<<< HEAD
Your version of the line
=======
Their version of the line
>>>>>>> main

Delete everything except your version:

Your version of the line

2. Keep their version

Their version of the line

3. Keep both

This is the most common case in contributors.md:

<<<<<<< HEAD
| Student | @student | Kazan |
=======
| Dmitry | @dmitry | Baikal |
>>>>>>> main

Need to keep both lines:

| Dmitry | @dmitry | Baikal |
| Student | @student | Kazan |

4. Write a new version

Sometimes you need to combine both changes or write a third option:

<<<<<<< HEAD
function getUserName(user) {
    return user.name;
}
=======
function getUserName(user) {
    return user.firstName + " " + user.lastName;
}
>>>>>>> main

Resolution: combine both improvements:

function getUserName(user) {
    return user.firstName + " " + user.lastName || user.name;
}

Conflict in a Pull Request

If a PR shows “This branch has conflicts”, you need to:

Method 1: Sync fork + Update branch (for forks)

  1. On GitHub: Sync fork → Update branch
  2. In GitHub Desktop: Fetch origin → Pull
  3. Branch → Update from default branch
  4. Resolve the conflict in the editor
  5. Commit → Push → PR will update

Method 2: Merge main into your branch

git checkout feature/my-feature
git merge main  # conflict will occur here
# resolve the conflict
git add .
git commit -m "fix: resolve conflict"
git push

Method 3: Via GitHub (simple conflicts)

GitHub sometimes lets you resolve the conflict right in the browser:
PR → “Resolve conflicts” → in-browser editor → “Mark as resolved”.

How to Make Sure Everything Is Resolved

After resolving:
- The file has NO lines with <<<<<<<, =======, >>>>>>>
- GitHub Desktop shows the file without the conflict icon
- The PR shows “No conflicts — This branch has no conflicts with the base branch” ✅

How to Avoid Conflicts

You can’t avoid conflicts entirely, but you can reduce their frequency:

Make small PRs

The fewer changes — the lower the chance someone touched the same file.

Regularly update your branch

git merge main  # update your branch from main once a day

Agree on who works with which file

If two people work on the same file — give each other a heads-up.

Merge PRs quickly

A PR that “sits” for a week accumulates conflicts. Merge faster.

Cancel a Merge and Start Over

If you get confused — you can cancel everything:

git merge --abort  # cancels the merge, restores state to before

In GitHub Desktop: click Abort merge in the warning panel.

Don’t Be Afraid of Conflicts

Conflicts are a sign of active team collaboration. The more developers work on a project — the more conflicts occur.

Knowing how to resolve conflicts quickly and correctly is an important developer skill. After a few times it becomes routine, taking 2-3 minutes.

Your reaction to the article

💬 Comments (0)

🔐 Sign in to leave a comment
🚪 Login
💭

No comments yet

Be the first to share your opinion about this article!

🔗 Similar

Similar articles

Continue learning with these materials

📝

Git Hosting Platforms: Full Comparison 🏆

GitHub, GitLab, Bitbucket — which one to choose? A complete comparison with up-to-date data.

📅 06.05.2026 👁️ 52
📝

What Is a Git Commit and Why Do You Need It? 📸

A commit is a saved snapshot of your project at a specific point in time...

📅 06.05.2026 👁️ 56
📝

Why Git won over every other version control syst…

Today Git is the de facto standard for version control in software development. But it...

📅 06.05.2026 👁️ 51

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!