Version control with git and Github

Nick George

[email protected]


  • Why do we need version control?
  • How do you use it (basics)
  • more resources

Why do we need version control?


by Jorge Cham,

Multiple code versions

  • Natural tendency to happen when coding
  • programming is an iterative process
  • main.m
  • main_nick.m
  • old_main.m
  • etc…


What's wrong with this?

This can be dangerous when running programs!

  1. Difficult to stay organized
  2. Hard to develop (dropbox will overwrite local changes if you update)
  3. What if you want to go back to a previous version to re-run an old analysis?

version control workflow

Bryan_2017figure1.png Bryan2017

  • Base version is saved
  • New versions get comments and diffs are recorded

Version control is a must in software development

Still… why?

But we aren't software developers…

cd ~/Dropbox/m\ new/drg
wc -l *.m

We develop software

cd ~/Dropbox/m\ new/drg
wc -l *.m
      38 drgBehaviorbyBlock.m     
    1142 drgMaster.m
     323 drgPercentLick.m
     194 drgProbabilisticTimecourse.m
     137 drgSpikePhase.m
     270 drgThetaAmpPhaseLick.m
     189 drgThetaAmpPhaseNew.m
     234 drgThetaAmpPhaseTrialRange.m
      23 drg_ecdf.m
      17 drg_pcolor.m
      26 drg_play_filters.m
     253 drgdFvsBFREncRetr.m
      22 getComputerName.m
     162 shadedErrorBar.m
    9401 total

9,000+ Lines of code in one directory!

Version control is a must in software development

"I don't need version control, I work alone"


What is it version control?

Version control as an "Oh ** I broke it" insurance

git checkout old-version


Version control as a record

  • all changes
  • who made them
  • your helpful commit message.
  • Example video coming soon. see software carpentry in the meantime

What is git?

  • git is a version control system (there are many others…)
  • written by Linus Torvalds, the creator of the Linux kernal
  • git lives locally on your machine
  • git stores your code in a repository
  • with a few commands, you can use git to track your work


  • GitHub is a cloud hosting service for git repositories
  • GitHub copies your local repositories to the cloud
  • Allows you to collaborate with others on the same code base

Interface for collaboration


  • With git, you can easily compare differences between files on a commit by commit basis.

Interface for collaboration

  • Git keeps track of who made the changes and when they were made.
  • git and Github make working on code as a team easier.

How will you use it?

  1. Install git
  2. Configure git
  3. Make a github accound
  4. Clone
  5. Sync
  6. Contribute

1. Install git

Follow the Github guide

install git

2. Configure it

git config --global "Nick George"
git config --global "your-email"

3. Make a github account

4. Fork and clone


4. Fork and clone

  • Click the repository (collection of code files) you want and click clone or open in desktop on the top right corner
  • Clone in Github desktop or with ssh/https


4. Fork and clone


  • Cloning copies from Diego's page.


  • forking makes a local copy of Diego's repository
  • Now go to your copy and hit clone or open in desktop

5. Staying up to date

Github Desktop


5. Staying up to date

Developers will have to set the remote… more coming soon

In a terminal

cd ~/Github/drta
git pull

6. Contribute

For developers!

developer guides coming soon

  • Code normally, but…
  • stay up to date with git pull
    • details in developer guide
  • use git commands
    • git add
    • git commit
    • git push
  • Create pull requests to add your changes to the main code base


As a team

Personal vs organization account

We can set this up a few different ways…

  • Diego's personal account
    • we fork, push, and pull as guests

Organization account



  • More advanced guides coming as we need them
  • the most important part to staying up to date is merging


Highly recommend:

How is this different from dropbox or google versions?

  • you can see diffs
  • Pick the files or changes to go back to
  • Previously discussed metadata

Sources of error

Merge conflicts

  • If the remote (main version from Diego) and your version both have changed files and you try to merge…
  • You will get a merge conflict.
  • git will not guess which change you want, it will just say you have a problem and make you fix it.
  • See the upcoming lab-developer-guide for avoiding these errors


Version control

Version control systems save the base file, then just records changes

Sorry, your browser does not support SVG.

  • Space efficient (only saving diffs)
  • ONE base version


Sorry, your browser does not support SVG.


Sorry, your browser does not support SVG.