What to do when Git throws you conflicting changes

In the hustle of collaborative software development, encountering conflicting changes in Git is a common occurrence that can give a hard time even to the most seasoned developers.

Problem

Sometimes, when you try to commit your changes, Git slams on the brakes with a dreaded “Conflicting Changes” message.

Now what?

Solution

Here’s a step-by-step guide for navigating through conflicting changes:

  1. Assess the Situation: Take a moment to understand the nature of the conflicts. Git is simply flagging areas where changes from different branches clash. It’s not the end of the world—just a bump in the road.
  2. Sync Up and Suit Up: Before diving into conflict resolution, ensure you’re working with the latest changes from the remote repository. Use git pull to sync your local repository and suit up with the freshest code.
  3. Engage in Conflict Resolution: Open the conflicted files in your trusty code editor. Git has marked the conflict markers (<<<<<<<, =======, >>>>>>>), highlighting the areas of contention.
  1. Conquer Conflicts Manually: Review each conflicting section carefully. You’ll need to decide which changes to keep, discard, or merge together. This may involve selecting one version over the other or crafting a blend of both.
  2. Tidy Up the Battlefield: Once conflicts are resolved, remove the conflict markers and ensure the file is left in a clean, coherent state.
  3. Stage, Commit, and Push: With conflicts vanquished, it’s time to stage your changes with git add, commit them with a descriptive message, and push your code back to the remote repository.

With these steps, you should be able to solve conflicting changes thrown by git.

Hope you find this helpful! If you enjoyed the content or found it useful and wish to support our efforts to create more, you can contribute towards purchasing a Star Wars Lego for Sandro’s son!

Author: Diogo Formosinho

Diogo Formosinho is a Enterprise Integration Consultant at DevScope

Leave a Reply

Your email address will not be published. Required fields are marked *

turbo360

Back to Top