DEV Community

Cover image for Git Conflict resolution made simple
José Muñoz
José Muñoz

Posted on

Git Conflict resolution made simple

Have you ever tried to merge a Pull Request and it seems to have a conflict on file that you changed intentionally?

When it comes to conflict resolution, it can be a painful experience sometimes, even when you all you’re doing is accepting the incoming changes.

Git can be intimidating sometimes, and most people tend to prefer a GUI to manage their versioning and source control. But sometimes using the CLI can be the better option.

I’m the kind of weird that likes to do things on the CLI when possible, so I have a small life-hack that has saved me so much time during conflict resolution.

In this example we are going to imagine we are trying to make a PR from development to staging, once you’ve created the PR you notice there is a few conflicts and the PR can’t be merged right away. Don’t panic, we can fix this with the power of the CLI!

Make sure you have the latest version of your destination branch (in this case staging) checked out on your local environment.

Go to your source branch (in this case its development) and run:

git pull origin staging —strategy ours

This will accept the history of the source branch over the destination branch and resolve the conflicting files for you. Now you can safely push the resolution to your remote and the PR you submitted should now be mergeable.

The CLI can be an intimidating place, but sometimes it can be the fastest way to achieve a task. Merge strategies are one of the most powerful options you can use from the git source control system, and there’s many more strategies that allow you to get even more flexibility from these options, I’ll leave a couple of links below where you can learn more about git merge strategies, thanks for reading!

Links:

Top comments (1)

Collapse
 
moblimic profile image
Michael Craddock

I love little git tips like this. Will have to read more into this myself. Thanks!