DEV Community

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

Posted on

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

Top comments (0)