DEV Community

Cover image for Git & GitHub made simple - Resolving merge conflicts
Francesco Di Donato
Francesco Di Donato

Posted on

4 2

Git & GitHub made simple - Resolving merge conflicts

You know how to create branches on Git and how to complete the related PR (do you?)However, you ran into something you weren't ready for - Merge conflicts.

Let's set up a simple situation to grasp the concept more easily: in the master branch you have this index.html.

index.html(master branch)
<div>
   <p>I like:</p>
   <ul>
      <li>dogs</li>
      <li>sea</li>
      <li>summer</li>
   </ul>
</div>
Enter fullscreen mode Exit fullscreen mode

In another branch named overriding-branch the same index.html present:

index.html(overriding-branch branch)
<div>
   <p>I like:</p>
   <ul>
      <li>cat</li>
      <li>mountain</li>
      <li>winter</li>
   </ul>
</div>
Enter fullscreen mode Exit fullscreen mode

On both branches, both files are committed to their origin - if you make a change to the file without committing, the moment you change branch and this last already has something in that line you will get this error
git_error

So, being in the master branch, enter the command git diff overriding-branch.
git_conflict
And immediately you realize that the two files are not overlapping. In fact, by running git merge master.
git_merge_conflict

And it is no coincidence that the file in your IDE has changed like so:
git_conflict_VS

Then you can resolve the conflict using the links above:

  • Accept Current Change - keep the version of the branch you were on at the time of merging
  • Accept Incoming Change - use the version of the branch with which the merge is required
  • Accept Both Changes

Otherwise, you can manually intervene directly in the IDE:
git_manually_resolved_conflict

Of course, you now need to commit and push the updated file:
git_merge_conflict_pushed


You got carried away and made a commit you shouldn't have done? Don't despair, going back is ... within console reach. That's how it is done [VERY_VERY_SOON].
Otherwise, take a look at the concept of the fork [VERY_VERY_SOON].


🐤 twitter: https://twitter.com/did0f

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more