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. Switch from the main branch to the taskBranch branch using one of these methods:

  • Switch to a branch using the Source Control panel Source Control icon - (Since R2026a) In the Branch field, select the branch from the list. If the Source Control icon is not in the sidebar, click the Open more panels button Open more panels icon and select the Source Control panel.

Branch switcher in the Source Control panel

  • Switch to a branch using the Branch Manager - In the Files panel, right-click and select Source Control > Branch Manager. Alternatively, use the Source Control panel to open the Branch Manager . To switch to taskBranch, in the Branch Manager toolstrip, in the Current Branch section, select taskBranch from the available branches.

Branch Switcher in the Branch Manager toolstrip

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

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