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).
Merge conflicts can traditionally cause developers a lot of grief, especially when working in the terminal, but GitKraken’s merge conflict tool helps users identify where the conflict is occurring and how to resolve it.
Watch this quick video or keep reading to learn more!
Download our Git GUI client for free, to easily resolve merge conflicts.
What is a Git Merge Conflict?
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 Merge Conflicts Occur?
Merge conflicts can happen when merging a branch, rebasing a branch, or cherry picking a commit.
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.
Resolve Merge Conflicts with GitKraken
While merge conflicts can be intimidating, they’re a snap with GitKraken.
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.
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.
Pro Tip: having the ability to edit code directly in the output box is a feature exclusive to GitKraken Pro.
Merge Conflicts with Deleted Files
As a second example, let’s say you attempt a merge where a file is deleted on one branch but not the other.
This will also trigger a merge conflict, but when you click to view the conflict, GitKraken will instead ask you to choose between three options:
- Keep Modified Version will tell GitKraken to add back the deleted file along with any changes you made to that file.
- Delete the File will tell GitKraken to delete the file and discard any of its changes.
- And Keep Base Version will tell the app to add back the deleted file without any added changes from a branch.
After making your selection, you may commit and merge to proceed.
Easy Merge Conflict Resolution!
See, merge conflicts aren’t too bad, right!? Now you have the tools and expertise needed to resolve merge conflicts with the help of the GitKraken Git Client.
Stay on the cutting edge of software development by getting innovative tips, trends and stories delivered to your inbox every month!