Make MATLAB & git play well together
If you have been wary of setting up a source control system in the MATLAB environment because trying to leaves you stupefied and a few hours older with little to show for it, you are not alone. As documented here, here and here.
Iโm sure there are plenty of reasons why source control has been difficult for amateur programmers, but learning git is worth transcending the learning curve. Branching/merging/rebase maneuvers donโt require you or your collaborators to be connected at all times, freeing you up to work in airplanes and trains without internet connectivity.
You can read a blow-by-blow comparison of git with its competitors on โWhy git is better than Xโ, if you need more convincing.
If youโre beginning to get serious about source control for your MATLAB projects, here is a function that might be useful to you: git.m
A thin MATLAB wrapper for the git source control system
Short instructions
1. Get the open-source git executable for your OS.- Download git.m to your MATLAB path and use
git
at the MATLAB prompt exactly as you would use the OS command prompt.Long instructions
Here's a common MATLAB workflow to create your git repository, add a few files, modify them, and commit your changes:
Creates initial repository tracking all files under some root folder
1 | cd ~/ |
Shows changes made to all files in repo (none so far)
1 | git status |
Create a new file and add some codE
1 | edit foo.m |
Check repo status, after new file created
1 | git status |
Add foo.m to your repo
1 | git add foo.m |
Commit your changes to a new branch, with comments
1 | git commit -m 'Created new file, foo.m' |
Other useful commands (replace ellipses with appropriate args)
1 | git checkout ... % To return to an earlier node in branch |
This is not meant to be a comprehensive guide to the many possible git workflows. Take a look at the original git documentation or one of the other related resources below.
- GitX: A visual interface for Git on the OS X client
- github.com: Remote hosting for Git repos
- Everyday git with 20 Commands or soโฆ