Main Content

Automatically Merge Models

You can enable MATLAB® Git™ integration to automatically merge branches in your Git repository using the mlAutoMerge Git plugin. The plugin can automatically merge branches that contain changes in different subsystems, Stateflow® charts, and configuration sets in the same SLX file.

Tip

The mlAutoMerge Git plugin automatically merges your model files and resolves conflicts when you are working in different subsystems.

If you are not working in different subsystems, you must merge and resolve conflicts manually. For more information, see Resolve Conflicts in Models Using Three-Way Merge.

The mlAutoMerge Git plugin automatically merges changes in a child subsystem of a modified subsystem. If the number of ports remains unchanged, child subsystems are independent of parent subsystems. The plugin does not report a conflict for nonfunctional changes such as window positions, open Editor tabs, and other graphical details.

To enable automerge for models in your Git repository:

  1. Run this command in MATLAB.

    comparisons.ExternalSCMLink.setupGitConfig();

    This command automatically populates the global .gitconfig file. An example follows.

    [difftool "mlDiff"]
       cmd = \"C:/Program Files/MATLAB/R2024b/bin/win64/mlDiff.exe\" $LOCAL $REMOTE
    [mergetool "mlMerge"]
       cmd = \"C:/Program Files/MATLAB/R2024b/bin/win64/mlMerge.exe\" $BASE $LOCAL $REMOTE $MERGED
    [merge "mlAutoMerge"]
       driver = \"C:/Program Files/MATLAB/R2024b/bin/win64/mlAutoMerge.bat\" %O %A %B %A

  2. Configure your Git repository to use the mlAutoMerge executable file for resolving conflicted SLX and MDL files on branch merges. Open the .gitattributes file in your repository and add:

    *.slx binary merge=mlAutoMerge
    *.mdl binary merge=mlAutoMerge
    You can enable automerge for other files such as SLREQX, SLMX, MLDTAX, and PSPRJX files.

Now, when you merge branches that contain changes in non-overlapping parts of the same SLX file, the mlAutoMerge handles the merge automatically.

You can also customize external source control tools to use the MATLAB Comparison Tools and automerge functionality. For more details, see Customize External Source Control to Use MATLAB for Diff and Merge.

Related Topics