Main Content

Make Changes and Merge Git Local Branch

You are collaborating on models that are under Git™ source control. You work on some changes in your local branch taskBranch. When you attempt to merge your branch into the main branch, merge conflicts occur in two model files.

1. Open the example to download the supporting files.

Files and Source Control panels grouped together. Files panel on top shows 2 unmodified model files under Git source control. In the Source Control panel below, the mouse cursor points to the Branch Manager button.

2. Open the Branch Manager and switch from the main branch to the taskBranch branch.

In the Files panel, right-click and select Source Control > Branch Manager. Alternatively, use the Source Control panel to open the Branch Manager . If the Source Control icon Source Control icon is not in the sidebar, click the Open more panels button Open more panels icon and select the Source Control panel.

To switch to taskBranch, in the Branch Manager toolstrip, in the Current Branch section, select taskBranch from the available branches.

Branch Manager with the toolstrip on top, the commit graph in the middle, and detail panes on the left and right. In the toolstrip, the mouse points to the taskBranch option in the Current Branch section.

Alternatively, in the Command Window, enter these commands.

repo = gitrepo;
switchBranch(repo,"taskBranch");

3. Make these changes to the sldemo_mdlref_counter and sldemo_mdlref_basic models and save the models.

  • In the sldemo_mdlref_basic model, in the Constant block C5, set the Constant value to 110.

  • In the sldemo_mdlref_counter model, change the Scope block name from ScopeA to Scope and in the Switch block Switch, set the Threshold to 0.25

Alternatively, in the Command Window, enter these commands.

topMdl = "sldemo_mdlref_basic";
refMdl = "sldemo_mdlref_counter";

load_system(refMdl);
load_system(topMdl);
modelNames=[refMdl,topMdl];
    
refBlockPath = append(refMdl,"/Switch");
set_param(refBlockPath,"Threshold","0.25");
refScopePath = append(refMdl,"/ScopeA");
set_param(refScopePath,"Name","Scope");
cstBlockPath = append(topMdl,"/C5");
set_param(cstBlockPath,"Value","110");

save_system(refMdl)
save_system(topMdl)

close_system(modelNames,0)

4. Commit your changes. In the Source Control panel, click Commit. Enter a commit message and click Commit.

Alternatively, in the Command Window, enter these commands.

commit(repo,Message = "Set Fixed step size to 0.003 and set InputSignalHandling and OutputSignalHandling to Auto/Zero-order Hold.");

5. Merge the branch taskBranch into the main branch. In the Branch Manager, switch back to main branch. Then, click Merge.

Alternatively, in the Command Window, enter these commands.

mainBranch = "main";
switchBranch(repo,mainBranch);
try
    merge(repo,"taskBranch")
catch
% The merge function throws an expected error because this branch merge
% results in a conflict.
% Unable to merge main into taskBranch.

% Caused by:
%    Conflicted files:
%    sldemo_mdlref_basic.slx
%    sldemo_mdlref_counter.slx
end

Files and Source Control panels grouped together. Files panel on top shows 2 conflicted model files. The Branch Manager prompts that the merge resulted in conflicts.

The branch merge results in conflicts in both model files. See the next steps to resolve the conflicts.

See Also

Topics