Goals of this presentation

  • Present the need for version control
  • Basic concepts of Git
  • Use cases of Git
  • What is not the goal

  • Convince you that git is the only solution
  • Go through everything together

Overview

  • Why is version control important
  • What is version control?
  • Key concepts of Git
  • What can git do for you?
  • What to git?
  • Social git
  • Resources

Why to control version?

Folder pizza as a bad example
Folder pizza

Why to control version?

Is it a bug or a feature?

Why to control version?

Transfer of code between team members?

What is version control?

Software aiming at storing different versions of files in a structured way

  • Every change is documented
  • History accessible
  • Everything structured

What is version control NOT?

  • Not a back-up system
  • Not the solution to all your problems

This sounds interesting...

source: General Buck Turgidson from dr. Strangelove

Most popular VCS

  • Client-server model
    • CVS (Concurrent Versions System)
    • SVN (Subversion)
    • ...
  • Distributed model
    • Mercurial
    • Git
    • ...

What is git?

  • Distributed version control system
  • Open source (GNU GPL2)
  • Initial release: 2005
  • Multiplatform (Linux, Win, Mac OS etc...)
  • Initialy designed for the linux kernel

Basic concepts of

Basic concepts of git

Repository

A collection of files that are being tracked for changes

  • Text files (ideally)
  • Binary files (not optimal, but possible)
  • Folders, subfolders...

Basic concepts of git

Staged files

A subset of changed files, that will be included in the new version

  • Not all revisions are mature for inclusion

Basic concepts of git

Commit

A collection of changes in individual files (i.e. version)

  • Identifying hash
  • Who
  • When
  • Commit message
  • Changes made

Basic concepts of git

Lifecycle

Basic concepts of git

Remote

Copy of the repository located in other locations

  • Multiple remotes for each repository
  • Each remote contains all history
  • Users can push changes to and fetch changes from remotes

Basic concepts of git

Branches

An independent line of development

  • Branches have common history
  • Branches can have sub-branches
  • Branches can be merged

How to ?

How to git?

  • Install git (http://www.git-scm.com/)
  • Choose a good GUI
    • Git gui
    • Github gui
    • TortoiseGit (right-click menu)
    • ...
  • Command line

How to git?

Creating a repository

Go to folder that contains the files for the repository

    git init

How to git?

Creating a repository

How to git?

Adding files to the staging area of the repository

When inside the repository

    git stage file1 file2 ... // (Adds file1 and file2 to staging area)
    git stage .               // (Adds all files and subfolders in current folder)
    git stage folder/         // (Adds all files in folder)

How to git?

Committing new versions

    git commit -m "Your commit message here"

How to git?

History log

    git log
    commit bc878077638d507e0acd895bb595cc94526ec542
    Author: Tassos Natsakis (nakano) 
    Date:   Fri Apr 3 16:00:23 2015 +0200
    
        "Adding function that reads pressure data and exports them in a CSV file,
        with the coordinates that they should be applied to, in a FE simulation"
    
    commit dff63cd96c10756ff6c429ca0e705bc6ca25228c
    Author: Tassos Natsakis (nakano) 
    Date:   Fri Apr 3 15:59:37 2015 +0200
    
        "Finding some more small bugs introduced when I was working in a hurry"
        ...

How to git?

History log

How to git?

Differences between commits

    git diff (filename) commit1 commit2
    diff --git a/peakAreaTalus.m b/peakAreaTalus.m
    index 4c5a518..4eab54a 100644
    --- a/peakAreaTalus.m
    +++ b/peakAreaTalus.m
    @@ -1,10 +1,10 @@
     function pressureArea =...
         peakAreaTalus (data, rows, cols, measPathName, legendNames,...
    -    rowSpacing, colSpacing)
    +    rowSpacing, colSpacing, toPlot)

How to git?

Differences between commits

How to git?

Checking out versions

    git checkout commit_hash

How to git?

Blame people

    git blame filename
    d96873d1 (jhbecker) 2012-06-10 13:39:56 +0200 108)
    d96873d1 (jhbecker) 2012-06-10 13:39:56 +0200 109) \DeclareComplementaryOptio...
    9c369fc5 (Wannes)   2013-01-10 13:17:15 +0100 110) % Cover options
    9c369fc5 (Wannes)   2013-01-10 13:17:15 +0100 111) \DeclareStringOption{cover...
    c813ae79 (Wannes)   2013-03-23 15:28:20 +0100 112) \DeclareBoolOption{coversh...
    c813ae79 (Wannes)   2013-03-23 15:28:20 +0100 113) \DeclareComplementaryOptio...
    9c369fc5 (Wannes)   2013-01-10 13:17:15 +0100 114)
    07c6d277 (Yves)     2010-09-02 22:53:52 +0200 115) % Default values
    c813ae79 (Wannes)   2013-03-23 15:28:20 +0100 116) \setkeys{adsphd}{info=true...

How to git?

Blame people

How to git?

Cloning an existing repository

You want to copy an existing repository and go on working on it?

    git clone https://location/of/the/repository
    git clone git@gitlab.mech.kuleuven.be:u0074517/git-overview.git //This presentation

How to git?

Create remotes

    git remote add name location //Add remote repository with location and name
    git remote add mech git@gitlab.mech.kuleuven.be:u0074517/git-overview.git
    git push name branch //Push changes to remote
    git pull name branch //Pull changes from remote

'Anorthodox'

Anorthodox cases for git

Word documents (binary)

Anorthodox cases for git

LabVIEW (using LabVIEW difftools)

Anorthodox cases for git

LaTeX documents (using latexdiff)

Social

Social git

GitLab/GitHub/Bitbucket

  • Remote repositories with a nice web user interface
  • Access control
  • Wiki pages
  • Issues

Social git

GitLab

  • Login with your MECH account
  • Set-up your SSH keys
    • Generate a key
    • Profile settings
    • SSH keys
    • Add SSH Key (you choose the name)
  • Create projects
  • Create remotes on your computer

Wrapping up

Why is this important?

  • For ZAP?
    • Keeps code documented, when PhD leaves
    • Easier involvement in projects (through issues)
  • For ATP?
    • Can be used as technical documentation
    • All code is stored in one location
    • Easy access control to the code (for new team members)
  • For BAP?
    • Helps you keep your projects cleaner
    • Check differences between versions
    • Fall-back to earlier versions

What is next?

Git hands on session

(Free) Resources