Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GitHub with MATLAB R2014b

Tags:

git

github

matlab

As you may know, we have source control in MATLAB R2014b. I want use GitHub with Matlab R2014b. In MATLAB, there is a manual for Git. The instructions for third-party source control tools state:

If you use third-party source control tools, you must register your MATLAB and Simulink® file extensions such as .mat, .mdl, and .slx as binary formats. If you do not register the extensions, these tools can corrupt your files when you submit them by changing end-of-line characters, expanding tokens, substituting keywords, or attempting to automerge. Corruption can occur whether you use the source control tools outside of MATLAB or if you try submitting files from MATLAB without first registering your file formats.

What should I do for this? In MATLAB we should set the "repository" and "sandbox". How can I set these on GitHub (particularly the "sandbox")? I should create repository with MATLAB or GitHub? How can i link the repository to second one?

Is 'Sandbox' in MATLAB same as 'Clone' in GitHub?

like image 315
Eghbal Avatar asked Oct 31 '14 14:10

Eghbal


People also ask

Can you connect MATLAB to GitHub?

You can use Git™ source control in MATLAB® to manage your files and collaborate with others. Using Git, you can track changes to your files and recall specific versions later.

How do I commit from MATLAB to GitHub?

When you want to commit changes, select the Modified files view to view files, and on the Project tab, click Commit. The changes are committed to your current branch in your local repository. Check the Git pane for information about the current branch.

How do I push a MATLAB project to GitHub?

Add a Project to Git Source ControlIn the Add to Source Control dialog box, in the Source control tool list, select Git to use the Git source control tool provided by the project. Click Convert to finish adding the project to source control. Git creates a local repository in your sandbox project root folder.


2 Answers

This image demonstrates the workflow of Git in MATLAB.

Git workflow for MATLAB

As you can see, you will work in your local directory which is your Sandbox. From there you will be able to commit changes to your local repository. They can then be pushed to a remote repository e.g. GitHub.

You can choose to clone a remote Git repository or create a new one.

I recommend you create a new repository on GitHub and then use the clone link to create the local repository from within MATLAB. This will clone the empty repository into your working directory. This local copy is called the Sandbox. You can start to work with these files and modify them. Once you've reached a certain milestone you can commit the changes to your local repository. This will then be ahead of the remote repository (GitHub). You can then push these commits to your remote repository (or fetch other commits pushed by others to the remote repository).

After you've added a repository you first need to register your binary files; Create a gitattributes file in your repository and add the following content;

*.mat -crlf -diff -merge
*.p -crlf -diff -merge
*.slx -crlf -diff -merge
*.mdl -crlf -diff -merge

These lines specify not to try automatic line feed, diff, and merge attempts for these types of files.

You can also check for other file types you use that you also need to register as binary to avoid corruption at check-in. Check for files such as .mdlp, .slxp, MEX-files (.mexa64, .mexmaci64, .mexw32, .mexw64), .xlsx, .jpg, .pdf, .docx, etc. Add a line to the attributes file for each file type you need;

*.mdlp -crlf -diff -merge
*.slxp -crlf -diff -merge
*.sldd -crlf -diff -merge
*.mexa64 -crlf -diff -merge
*.mexw32 -crlf -diff -merge
*.mexw64 -crlf -diff -merge
*.mexmaci64 -crlf -diff -merge
*.xlsx -crlf -diff -merge
*.docx -crlf -diff -merge
*.pdf -crlf -diff -merge
*.jpg -crlf -diff -merge
*.png -crlf -diff -merge

You can find more information here: http://www.mathworks.nl/help/matlab/matlab_prog/set-up-git-source-control.html

After that you can mark files for addition and commit modifications to your local repository. If you want you can also push and fetch to a remote repository.

Note that if you want to merge branches you will need to install a command-line Git client if you don't already have one.

like image 151
0xMB Avatar answered Nov 04 '22 00:11

0xMB


Explicitly specify those files as binary in the .gitattributes file:

.gitattributes

# MATLAB/Simulink binary formats
*.mat  binary
*.mdl  binary
*.slx  binary
# etc..
like image 2
Amro Avatar answered Nov 03 '22 23:11

Amro