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!