AI Hints
Home›Git & GitHub Tutorial›Pulling in a Team
Git & GitHub · Lesson 65 of 144

Conflicts When Pulling

Same line, two people.

⏱ 2 min read▶ Video at 1:10:46🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

Conflicts don't only happen between your own branches. If you and a teammate change the same line, and they push first, your pull will stop with a conflict. Good news. You already know how to fix it.

Conflicts When Pulling
From the video: Conflicts When Pulling
  • You and a teammate
  • Same line, both changed
  • Pull stops with a conflict

The conflict

Alex changed the title and pushed. We changed the same title, to our full name, and committed. Now we pull. Git fetches Alex's commit, tries to merge, and reports a conflict in index dot HTML. The file has the familiar markers. Our version, from head, and Alex's, from the commit we just fetched.

git
git pull
From https://github.com/sam/my-site
   f63a17a..55e2160  main       -> origin/main
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
head -5 index.html
<<<<<<< HEAD
<h1>Sam Lee</h1>
=======
<h1>Alex and Sam</h1>
>>>>>>> 55e216046f2ee92e8af501a3a5bd62e7ebc8d991

Fix, commit, push

Exactly like before. In our editor, we choose a final title, and remove the markers. Then add, commit, and push. GitHub now has both commits, joined by our merge commit.

git
cat index.html
<h1>Sam Lee and Alex Kim</h1>
<p>Welcome!</p>
<a href="about.html">About</a>
git add index.html
git commit --no-edit
[main 74a1d13] Merge branch 'main' of https://github.com/sam/my-site
git push
To https://github.com/sam/my-site.git
   55e2160..74a1d13  main -> main

Summary

A conflict when pulling is fixed just like any merge conflict. Edit, add, commit, then push. Next, another way to pull, that keeps history in a straight line.

Key takeaways
  • Conflict on pull? Same fix
  • Edit, git add, git commit
  • Then git push
Next up: Pull with Rebase — a straight-line history