50+ Professional developers
Shopware Silver & extension partner
80+ Shopware Advanced Certificates
200+ E-commerce Projects
A merge conflict happens when Git is unable to automatically resolve differences in code.
Whenever I see the word conflict when using Git, it feels very intimidating and scary. Something most developers hate to run into and try to avoid like the plague. However, trying to avoid merge conflicts on Bitbucket is not a way to solve problems. The best solution is to take your time and understand why the merge conflict happened and how to resolve it.
A merge conflict happens when Git is unable to automatically resolve differences in code. This can be between two commits or branches. The reason for this is that there are conflicting changes to the same line of code or document. So Git gets confused and does not know which version you may want to keep or discard. In this case, there is a need for human intervention. A classic scenario of this will be when Developer A makes changes to a file named ‘custom.js’ and when it is time to push the changes to the develop branch, it turns out Developer B made similar changes to the same file, which has been committed and pushed to GitHub. Now a merge conflict occurs.
It’s important to state that the process of resolving a merge conflict can be deleted if you want to improve and start over. In this case, you should use: git merge –abort So you can’t go wrong when merging a conflict by using this method. You can always start over clean slate.
After creating a PR, Git will highlight the conflicted areas, and ask which code you wish to keep.
This is not the only way a merge conflict can occur. A second scenario where this can happen is when you merge another branch into your working branch. In this case, we are merging the main branch into our development branch using git merge main.
Scenario 1: On Bitbucket when raising a PR request
The resolve conflicts button opens up an interactive editor where you can see Incoming Change and Current Change. Git is smart enough to highlight the points of the conflicts we need to resolve by using arrowhead symbols. <<<<<<<<<< — Incoming Change: Represents the changes you made in your branch that you would like to merge in. >>>>>>>>>> — Current Change: Has the changes in the current branch you want to merge into. These two changes are normally separated with `==========`. Accept incoming changes if you would like to keep your changes instead, or current change if you want to discard your changes. There is also a ‘keep both changes’ option if that applies. NB: It is always a good idea to ask for help from another team member if you are unsure what changes should be kept or discarded.
If you want to know more about e-commerce development platforms or apps, read our blog posts for Shopify and Shopware. Our dedicated outsourcing team can be your collaborator in ecommerce.