Use Source Control with MATLAB Projects
When you track your work using a project-based repository, you can perform source control operations directly from MATLAB®, similarly to how you perform source control from any repository. A project-based repository is a repository that also contains a MATLAB project to manage the path and settings. You can use Git™ or Subversion® (SVN) to track project files with source control.
To interact with source control, use the Project and the Source Control panels. You
can access source control options from the Project toolstrip, the context menu in the
Project panel, the context menu in the Source Control panel, and the More source control
options button in the Source Control panel. If the Source Control and the Project
icons are not in the sidebar, click the Open more panels button
and add them.
To start using source control to track project files, use any of these workflows:
Add an existing project to Git source control – Initialize a local Git repository in the project root folder. For more information on how to initialize a local Git, see Create Local Git Repository in MATLAB.
Retrieve a working copy of a project hosted on a remote repository – For projects under Git source control, see Clone Git Repository in MATLAB. For projects under SVN source control, see Work with Files Under SVN in MATLAB.
After you clone or check out a working copy of a project hosted on a remote server, open the project by downloading the PRJ file.
Create a new project in a folder already under source control – If you create a new project from a folder that is already under source control, MATLAB automatically adds the new project to source control. For instructions on how to create a new project from an existing folder, see Create Project from Existing Folder.
You can use this workflow if you want to create a project from files hosted on a remote repository. After you clone or check out a working copy, create a project from the repository root folder. Then, push or commit your changes to the remote repository to make the project accessible to collaborators.
Share your project on GitHub® – You can put your project under Git source control and create a GitHub repository in one step. For more information, see Share Projects.
Perform Source Control Operations
In a project under source control, you can perform source control operations in MATLAB, similar to any other folder under source control. You can access source control options in:
Project toolstrip
Context menu in the Project panel
Context menu in the Source Control panel
More source control options button
in the Source Control panel
Warning
For folders that contain projects, it is a best practice to open the project and use the Project panel instead of the Files panel. The Files panel is not aware of project features such as autorenaming or of information stored in project definition files.
For projects under Git source control, see Git in MATLAB.
For projects under SVN source control, see SVN in MATLAB.
Review Modified Project Files
You can identify modified or conflicted folder contents using the source control summary status in the Project panel. When you point to the file source control status, a tooltip displays if the file is modified, conflicted, added, deleted, or not under source control.
To only see the list of modified project files, use the Modified Files list in the Source Control panel.
Refresh list of modified files – If you make changes to files outside of MATLAB, to update the list of modified files, refresh the source control status. In the Project toolstrip, in the Source Control section, click Refresh. Alternatively, in the Source Control panel, select the option from the More source control options button
> Refresh.
View local changes – To view local changes in a file, in the Project panel, right-click the file and select Source Control > View Changes. Alternatively, in the Source Control panel, in the Modified Files list, right-click the file and select View Changes.
View revision history – To view the revision history of a file, in the Project panel, right-click the file and select Source Control > Show Revisions. Alternatively, in the Source Control panel, in the Modified Files list, right-click the file and select Show Revisions.
For projects under Git source control, you can use the Branch Manager to view the commit graph.
Compare revisions – You can also compare different revisions of the same file. In the Project panel, right-click the file and select Source Control > Show Revisions. In the Log for
file
dialog box, select two revisions and click Compare Selected.
Before you commit modified files to source control, you can run project checks. Project checks help you identify and fix issues, such as files that are under source control but not in the project, or derived files checked into source control. For more information, see Run Project Checks and Work with Derived Files in Projects Under Source Control.
To commit modified files to source control, see Review and Commit Modified Files to Git or Commit or Revert Changes to Modified Files under SVN Source Control.
Review Changes in Project Metadata
You can review changes in project metadata stored in the project definition
files similarly to the way you review changes in other project files. You can
review changes to shortcuts, labels, and project descriptions. The project
stores this information in XML files in the resources
folder.
For more information about project definition files, see Project Definition Files.
You can identify modified or conflicted project definition files in the
resources
folder using the source control summary status
in the Project panel. For large projects, to see only the list of modified
project files, use the Modified Files list in the Source
Control panel.
To review changes in a single project definition file, in the Project panel, right-click the file and select Source Control > View Changes. Alternatively, in the Source Control panel, in the Modified Files list, right-click the file and select View Changes.
The Comparison Tool opens a text comparison report.
Tip
Starting in R2025a, when you compare folders, MATLAB detects whether they are project root folders. The Comparison Tool opens a project definition files comparison report. For more information, see Compare MATLAB Projects.
Work with Derived Files in Projects Under Source Control
It is a best practice to omit derived and temporary files from your project or
exclude them from source control. To check if derived or temporary files are part of
your project, in the Project panel, in the Project toolstrip, click
Project Issues. In the Project Issues panel, in the
Checks tab, click Run Checks. If you
add the slprj
folder to a project, the project checks advise you
to remove this from the project and offer to make the fix. The derived files check
is only enabled if the project is under source control.
It is a best practice to exclude derived files such as .mex*
,
the contents of the slprj
folder, the sccprj
folder, or other code generation folders from source control, because they can cause
problems. For example:
With a source control system that can do file locking, you can encounter conflicts. If the
slprj
folder is under source control and you generate code, most of the files in theslprj
folder change and become locked. Other users cannot generate code because of file permission errors. Theslprj
folder is also used for simulation via code generation, so locking these files can have an impact on a team. The same problems arise with binary files, such as.mex*
.Deleting the
slprj
folder is often required. However, deleting theslprj
folder causes problems such as “not a working copy“ errors if the folder is under some source control tools.If you want to check in the generated code as an artifact of the process, it is common to copy some of the files out of the
slprj
cache folder and into a separate location that is part of the project. You can then delete the temporary cache folder when you need to. Use thepackNGo
(MATLAB Coder) function to list the generated code files, and use the project API to add them to the project with appropriate metadata.The
slprj
folder can contain many small files. This can affect the performance of some source control tools when each of the files is checked to see if it is up-to-date.