How to - Merge
What is actually Merge
Programming is a team sport, so it often happens that you work in a team on a joint project. However, you don't always program together, but often split up into different tasks. How you can still work in the same code is possible thanks to merge. Merge is the merging of your code with that of your team, so changes made by you and your team are merged into one code, which then acts as another code base.
Merge explained in the example
You have just fixed a bug in the previous program, while the rest of your team has added a method to the code, for example. Now your team has a different code base than you (you are missing the method they programmed), so what now?
-
first, your team should commit and push their current status (if you are unsure, take another look here)_
-
now you can pull the current state of the team (i.e. "download")
-
now you can right-click on the latest version of the code (the one that has just been pushed by your team) to open a drop-down menu.
- if you and your team have not changed anything in the same piece of code, you are now done with the merge and can skip to step 7 in the tutorial. However, if a window similar to the following appears, you have a so-called merge conflict that you must resolve before you can continue:
-
since your program notices that your current code is different from that of your team, a merge request is made (i.e. a request to merge your code with that of your team). Intellij already gives you templates for the end product.
-
now search for the end product, which contains both your change and the extension of your team and select this as the end product of the merge. (Changes in the code are marked in color)_
-
after the merge is complete, you should now commit and push the merged code. Now your team can push the code again. This way, everyone in the team has the same code as a basis for further programming.