Lesson 5-2
How to Prevent Merge Conflicts
Keep in mind that Git tries to make it to where you don't create merge conflicts, because they can be a minor inconvenience, but it is important to remember to do a git pull BEFORE and AFTER you do any work. In fact, doing a git pull is the best way to prevent merge conflicts. So, do git pulls frequently and make sure your code is up-to-date with github.com.
Another great way to prevent merge conflicts is by working on a file at a different time. If you're on a development team, generally one person or two will share the same file(s) to work on. Try to coordinate with your teammates to make sure you can commit changes at a certain point, and then let your teammates know when you are done/committed & pushed the file(s).
Try not to add stuff to the end of files, or beautify your code if you're in the middle of development. This can not only cause confusion, since moving code lines around will move where something was written, but also will make it different from what your team created originally.
The last tip I can give is to push often. Though it may seem that pushing too much can easily create a merge conflict for others, it actually allows others to see what you have added quickly, and when someone does a git pull, they are doing a pull for all new changes, not just a specific version. So try to git push as often as you can.
Understand that merge conflicts can be created by various types of issues in collaboration, but it all boils down to when git sees 2 or more versions of a file, it needs to know which to keep, and which to discard. This can occur with multiple files or even entire directories, so you will have to go in and fix it all manually.
In the next section, I will show you how to fix a merge conflict.