git problem while simulink file is open

3 views (last 30 days)
Ali
Ali on 28 Sep 2017
Answered: Swastik Sarkar on 2 Aug 2024
I'm using git for source control in Simulink.
The problem is Simulink locks all open files, and whenever I want to do any operation in git which changes the files, I should close all Simulink files which are open in that git repository. do the operation and then again open all of the changed files. This takes time and is very annoying.
Is there any workaround for this, most programs and editors that I use with git allow git to change the open files and refresh after change is detected. here is a simple example, there are two git branches, master and dev, if currently dev is active and I want to checkout to master branch I get this error:
$ git checkout master
error: unable to create file file1.slx: Permission denied
Switched to branch 'master'
It actually gets worst, although git can't change the file it checks out to master branch anyway and now we have the file from dev branch in master branch!

Answers (1)

Swastik Sarkar
Swastik Sarkar on 2 Aug 2024
Hi @Ali,
When working with version control systems like Git, one should ensure that files are not locked or in use by other applications, to close all open files in MATLAB, use the following command:
fclose("all")
Refer to the below MathWorks documentation link to read more about “fclose” function:
You can also set up a “pre-checkout hook” in Git to ensure that all necessary files are closed before performing Git checkout.
You can read more about Git hooks here:
Hope this helps!

Categories

Find more on Source Control in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!