How to minimize git merge conflicts?

Our company uses git to track document / code changes, with a few people making changes and moving to a central repo. Most of them are newbies when it comes to git or command line tools in general. For them, we have scripts for updating or publishing a local repo after making changes.

Are there any workflows that work best for such situations in order to minimize merge conflicts that should be sorted out by someone more experienced with git?

+4
source share
4 answers

Git is not a substitute for proper development methods. It will not be better for you.

If two developers relate to the same code, git has no way to simplify its work, if it is a merge conflict, it will not matter if you are on a branch or not.

Short-term solution: use the correct local and remote branches to encapsulate work with various functions. Use branch branches (or github pull requests) to view feature sets and help resolve differences and conflicts.

Long-term: fix your code, adapt it to your team and vice versa, and use proper development methods.

+4
source

Nothing magical. Mostly discipline.

If people need to do something like pull requests or wait for commits to be reviewed before merging with some kind of β€œmain” repo or branch, try to make the time for review as short as possible.

You should probably try to shorten the life of the branch, but it really depends on the type of project you are working on.

Make the rule that all commits should be as small as possible. Make this rule that commits, should change only one. Make a rule not to mix cosmetic changes (for example, spaces) with functional changes and significant refactoring. (Don't ban whitespace changes completely - just separate them from other changes.)

In addition to version control, try assigning tasks to the coders in such a way as to reduce the likelihood that they change the same code in the same week or so.

+2
source

The main cause of merge conflicts is the time between each merge .
The longer you wait between each merger, the more you can see merge conflicts.

You can minimize this by choosing a merge workflow (for example, git flow for example), which will favor a branch for a function and make it easier to isolate tasks.
But while using a common set of files (in two different designs), you will encounter merge conflicts, especially if you have been waiting too long.

So, with distributed VCS, learn to publish regularly (push / pull) and learn to reba before merging .

This will not only reduce the number of conflicts, but also reduce the number of semantic conflicts : these are mergers that seem automatic (without conflicts), but generate the wrong code.
See " Better, a simpler example of" semantic conflict "? ".

+2
source

This article is written to help you better understand the " Successful Git Branching Model ." It states that you should separate the different types of branches, which include:

  • master
  • corrections
  • free branches
  • Development
  • function branches
0
source

Source: https://habr.com/ru/post/1446816/


All Articles