Versioning Git Matlab
Versioning Git Matlab
The information for this small guide was taken from the following websites:
http://benheavner.com/systemsbio/index.php?title=MATLAB_git
http://dasl.mem.drexel.edu/wiki/index.php/Git_Tutorial_-_Part_1
http://rogerdudler.github.io/git-guide/
http://readwrite.com/2013/09/30/understanding-github-a-journey-for-beginners-part-
1#awesm=~oGRovPJT6emrJc
https://codio.com/s/docs/git/git-primer/
This goal of this short guide is to get a simple, working environment for using Git and MATLAB. The
command line is used, so no gui.
Pulling and pushing requests on GitHub will be done using the Gui bash command line.
The best way to learn Git is to create a simple project with a few files in it and then experiment like
crazy. You can play around with all the Git commands and sync with GitHub repos to your heart's
content without worrying about doing any coding.
During the installation it is important to enable use from the Wondows command line
In this way the Windows Path is adapted and Git can be used from within other applications like
MATLAB.
http://www.mathworks.com/MATLABcentral/fileexchange/29154-a-thin-MATLAB-wrapper-for-the-
git-source-control-system
Or from
https://github.com/manur/MATLAB-git
The git wrapper allows you to use the git commands from within the MATLAB environment.
Note: I use a folder on my C-drive containing special MATLAB utilities, this folder is added to the
MATLAB Path, such that the utilities, in this case the ‘git’ command is always accessible from within
MATLAB.
3
When starting with versioning, the project folder containing the MATLAB code need to be prepared
for Git.
When using Git, you will need to have a repository. You can start by creating a project repository on
your own local machine (laptop, desktop) first.
Assume your project directory will be called ‘MATLAB_codelifecycle’, and this folder will contain all
the code related to the project
o Go to the directory (use cd) and initialise Git on the directory with the command:
git init
At this point the hidden folder .git will be created in this directory and the Git repository is ready to
be used: Git commands are accepted.
If this is the very first time that git is used, some minimal additional configuring work needs to be
done. These steps can be found in any Git tutorial:
specifying your user name is usefule when committing changes, the user name will also be noted.
git config --global user.email “your_email@youremail.com”
email account is useful when using Github, use the email account that was used for signing up in
Github.
When using Github, you have to connect remotely to this repository, this can best done securely
with ssh keys. The steps that you need to perform are given at:
https://help.github.com/articles/generating-ssh-keys
2 WORKFLOW
your local repository consists of three "trees" maintained by git. the first one is your Working
Directory which holds the actual files. The second one is the Index which acts as a staging
area and finally the HEAD which points to the last commit you've made.
Once the repository initialized, a first file for this repository can be created.
Make sure you are in your git repository folder, then open up a text editor, or make the repository
folder your current folder in MATLAB
6
When the git wrapper is installed in MATLAB, you can use the Git commands inside the MATLAB
command window.
Git found 1 untracked file in the current folder. In order to get this file in the versioning system, it
must be staged, using the add command.
git add HelloWorld.m
Check the status of the repository again to see what changes you've made:
If the file is not yet committed, and you start already to make changes, Git will report it.
8
It will mark that the file is modified and not staged yet.
Change the initial code and start tracking changes to the project
10
Check the logging, and with the diff option you can track the differences in between the files.
After inspecting the code, you can return to the correct state with
git checkout master
git log
Pushing a repository, requires a remote repository. The basic command to add a remote repository
is:
git remote add <shortname> <url>
12
Shortnames are short, easy-to-remember names that make it easier to work with your remote repos
in the future
Note: there is a difference in accessing github using ssh-keys or using logon-id and password.
When pushing a local repository to a remote repository, you need to tell git on the local machine to
which repo on Github should be linked to.
Option 1: using ssh-keys
Now that a commit was made, the local repository can be synchronized with the remote server to
make your changes available. Moving commits from your a local repository to a remote repository is
done with git push
When you pull in from the remote, you may get a conflict warning. This will happen if someone else
has modified code in a way that Git cannot automatically resolve, usually because you have been
editing the same bit of code.
When this happens, you will need to resolve the conflict. If you open up the file, you will see
something like this
13
<<<<<<< HEAD:index.html
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> iss53:index.html
You simply need to remove the code block that you want to dispose of. The top block is your code
and the bottom comes from the code being merged. If you want to keep your code, you will want to
end up with
<div id="footer">contact : email.support@github.com</div>
To minimize conflicts, you should Commit little and often and Pull from the remote master often.