Search
Close this search box.

How to Resolve Merge Conflicts in Git

Advanced Git Tutorial

GitKraken’s in-app merge conflict tool will allow you to perform more advanced Git actions without the related risk – your solution is just a few clicks away.

Git Merge Conflicts

Watch this advanced Git tutorial video to learn more about merge conflicts in Git and when they occur.

When Git is unable to automatically resolve differences in code between two commits because there are conflicting changes to the same line of code, a merge conflict occurs. Merge conflicts in Git can happen when merging a Git branch, rebasing a branch, or cherry picking a commit.

See how to communicate with Git to resolve a merge conflict and proceed with your Git merge, Git rebase, or Git cherry pick.

What is a Git merge conflict?

When working in Git, users can combine commits from two different branches through an action known as merging. Files are automatically merged unless there are conflicting sets of changes (i.e. the commits update the same line of code differently).

A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits.

When all the changes in the code occur on different lines or in different files, Git will successfully merge commits without your help.

However, when there are conflicting changes on the same lines, a “merge conflict” occurs because Git doesn’t know which code to keep and which to discard.

When can a Git merge conflict occur?

Merge conflicts can happen when merging a branch, rebasing a branch, or cherry picking a commit.

where can merge conflicts occur

If Git detects a conflict, it will highlight the conflicted area and ask which code you wish to keep.

Once you tell Git which code you want, you can save the file and proceed with the merge, rebase, or cherry pick.

No matter whether your merge conflict occurs during a merge, rebase, or cherry pick, GitKraken will lead the way to a quick and easy resolution.

How do you resolve merge conflicts in Git with GitKraken?

While merge conflicts can be intimidating in the command line, they’re a snap with the GitKraken Git GUI.

Let’s say we have two branches that have modified the same line in the same file. When you drag-and-drop to perform a merge, GitKraken will detect the merge conflict and notify you that it needs your help.

GitKraken merge conflict editor

Click View Conflicts to view a list of conflicted files. Then, when you click a file, it will open the merge tool, showing you the conflicting changes between the two branches along with an output view at the bottom. You may check the box for each hunk of code you wish to keep or select the code one line at a time.

You can even type in the output box to fine-tune your code further. Once you’re satisfied with the changes, hit Save to exit the merge tool and proceed to the next conflicted file. After resolving all conflicted files, you may proceed with the merge.

Ready for easier merge conflict resolution in Git? The cross-platform GitKraken Git GUI has the robust features you need to safely scale Git across your projects and organization.

Additional Resources

Table of Contents

Make Git Easier, Safer &
More Powerful

with GitKraken

Visual Studio Code is required to install GitLens.

Don’t have Visual Studio Code? Get it now.

Team Collaboration Services

Secure cloud-backed services that span across all products in the DevEx platform to keep your workflows connected across projects, repos, and team members
Launchpad – All your PRs, issues, & tasks in one spot to kick off a focused, unblocked day. Code Suggest – Real code suggestions anywhere in your project, as simple as in Google Docs. Cloud Patches – Speed up PR reviews by enabling early collaboration on work-in-progress. Workspaces – Group & sync repos to simplify multi-repo actions, & get new devs coding faster. DORA Insights – Data-driven code insights to track & improve development velocity. Security & Admin – Easily set up SSO, manage access, & streamline IdP integrations.
winget install gitkraken.cli