Since the introduction of Git the world of version control went through a revelation. Currently Github is the biggest player in the field, offering a free place to host and collaborate on your open-source code. However Git is also very useful for a scientist to keep track of in silico experiments and it does not require any sophisticated or complicated tools. In this post a small tutorial on how to set Git up for your experiments. The biggest misconception about Git is that it requires you to setup some kind of “remote server” which you can synchronise to. Since Git is a “distributed version control system” it just runs on your computer and there is no requirement to connect to a external source. So what can you use Git for? I use it to track the pieces of code I write to analyse experiments. You remember the moment you produced an awesome graph a couple of weeks ago and now are already spending two hours in finding the correct parameters you used? With version control this problem is easy resolved since you can just trackback the changes you made to the code. If you are not familiar with the principles of Git itself like cloning, branch and commit, check out the tutorial here. I’ll use Matlab on a Mac to show how you can set Git up in less than 2 minutes:
- Download Git
- Download the Git “plug-in” for Matlab, it is just 30 lines of code to enable the git command in Matlab.
- Edit the Matlab “plug-in” to work on your system. (ie. set GIT_BINARY = ‘/usr/local/git/bin/git’; in git.m)
- If you don’t like the command line; Download GitX to track your changes in a GUI.
My work flow is really simple, the graphs a Matlab scrip are saved in a unique directory containing the branch name and the last commit text and hash code. So every time you branch off or commit a new directory is created. So assume you have written a Matlab file called PrettyGraph.m
>> git init %Initialise git in the directory >> git add PrettyGraph.m %Stage your file >> git commit -m "Initial commit" %Commit it
If you now want to branch off to a new development tree
>> git branch dev >> git checkout dev %And we are in a new branch
Run ici to get your current location
>>ici ans = dev_e13732d_Initial commit
Now you can for example use ici to store your current results in or to refer to in your labbook. A screenshot showing GitX a GUI for Git: A long, but energetic video of Github developer Scott Chacon showing all the ins and outs of Git.
Some more reads on this topic:
- A blog post explaining the commands a bit more
- About Git and Scientific Reproducibility
- The “Academic version” in PLOS Computational Biology, its about Version Control in general, not Git.