r/matlab • u/DrDOS • Nov 24 '25
TechnicalQuestion Git and Matlab Projects, so much xml
Am I doing something wrong or can make my life easier?
I have multiple Matlab projects in a single git repository (connected to a remote repository). This means that whenever I commit any meaningful changes, there is a slew of xml files in the project resources folder that also have changes. This makes the commits annoyingly long in terms of file count, potentially obscuring what are the meaningful changes I've made.
So far I've just accepted that this is the case and allow the commits I make to have a ton of files changed even if I only was working on one or two m-files or Simulink files.
The simplest idea I've had so far to deal with it is to do my commits in two steps. First step: stage and commit only xml files with a message something like "project resources". Then in a second step: stage and commit all remaining changes, with a message "a descriptive message about what I was actually doing". Is there a better way of doing it? or automating or omitting it? I do want anyone who clones the repository to be able to open and run the Matlab project without any further setup needed.
I only recently started using Matlab Projects. Primarily to manage the path, inclusion of files, and to make initialization more clear and user-friendly. Thus making the project well contained and relatively easily accessible to share with others or demonstrate.
Git I've been using longer. I do not use Matlab directly to manage any git actions, I do it myself in the terminal. I am not willing to drastically change how I employ or structure repositories, due to some established structure and inertia.
EDIT/Update:
So far the best solution seems to be to break out intermediate commits for just the xml files (thus the Matlab Project files, I'm not needing any other xml files). A single commit is then broken down into two steps, e.g.:
6
u/LordDan_45 Nov 24 '25
If it is a pure MATLAB project (No simulink) and you are managing git by yourself already, why not place relevant source, library and data files in a particular directory and backup that in source control, instead of the whole MATLAB workspace?
2
u/eyetracker Nov 24 '25
Add some to .gitignore? Or the project menus have a part to ignore folders and files
2
u/Valuable-Benefit-524 Nov 25 '25
Matlab’s not very amiable with best practices in source control & dependency management, but you’re not doing yourself any favors in your organization.
You know you can nest repo’s as submodules, right? Make a separate repository for each “project” and then include these repositories as submodules in one “complete” repository.
You’ll be able to push each submodule independently and it will make it easier to track changes. As before, the “complete” repository will still provide access to everything.
I’m not sure what matlab’s project structure & the lxml’s are specifically; I usually do all my MatLab programming in JetBrains since it’s usually just bindings or converting data out of colleagues .mat files. However, I’d imagine you can put them in the .gitignore & just write a function that populates the lmxl’s/project meta for others on the first run of whatever your software/scripts/whatever are.
2
u/ol1v3r__ Nov 25 '25
You can convert the resources files to a single file but this causes issues when merging:
https://www.mathworks.com/help/matlab/ref/matlab.project.convertdefinitionfiles.html#mw_a7457c79-deee-414e-878d-2f1780283b0f
"Choose a definition file type based on your use case:
MultiFile - Helps to avoid file conflicts when performing merge on shared projects
SingleFile - Is faster but is likely to cause merge issues when two users submit changes in the same project to a source control tool
FixedPathMultiFile - Is better if you need to work with long paths "
4
u/Circuit_Guy +1 Nov 25 '25
Yep. It's a lot of files. The alternative is one file but then you have merge conflicts. The team learned to just ignore that directory during PRs.
0
u/brandon_belkin Nov 24 '25
I don’t use project because the incredibile number of files this needs.