Code versioning

An introduction with Git

By Paul-Emmanuel Raoul / skyper@skyplabs.net / @SkypLabs

Creative Commons License

What is version control?

System that records changes made to a set of files over time

These systems are called VCS (Version Control Systems)

They are essential to programming projects involving several people

What can we do with that?

Keep every version of a file (source code, image...)

Work easily with several programmers

Revert files back to a previous state

Compare changes over time

And much more...

Different VCS architectures

Local

Centralised

Distributed

Local VCS

Simple local database

No connectivity

No collaboration

Example: RCS

Local VCS

Local VCS
Local VCS - Reference: Pro Git, 2nd edition

Centralised VCS

Made for dealing with the collaboration issue

One single remote server

Requires to know what other people are doing

Examples: CVS, Subversion

Centralised VCS

Centralised VCS
Centralised VCS - Reference: Pro Git, 2nd edition

Distributed VCS

Full local copy of the remote repository

Can deal with several remote repositories

Several types of workflows

Examples: Git, Mercurial

Distributed VCS

Distributed VCS
Distributed VCS - Reference: Pro Git, 2nd edition

Why using Git?

It's fast

Strong support of non-linear workflows

Ables to handle large projects efficiently

Most used VCS these days

Free and open source

Git basics

To initialise a Git repository in an existing directory:


git init
            

And to create a new one:


git init my-project
            

Git basics

If you want a copy of an existing Git repository:


git clone git@github.com:docker/docker.git
            

The above command line will clone the official repository of the Docker project

Git basics

Areas
Areas - Reference: Pro Git, 2nd edition

Git basics

To track new files:


git add *.c
git add include/
git add README.md
            

These files are now in the staging area

Git basics

And now, your first commit:


git commit -m "first commit"
            

Git basics

Lifecycle
Lifecycle - Reference: Pro Git, 2nd edition

Git branching

Git's "killer feature"

Incredibly lightweight

Designed to be used as often as possible

Basic branching

Basic branching 1
Basic branching 1 - Reference: Pro Git, 2nd edition

Basic branching

Basic branching 2
Basic branching 2 - Reference: Pro Git, 2nd edition

Basic branching

Basic branching 3
Basic branching 3 - Reference: Pro Git, 2nd edition

Basic branching

Basic branching 4
Basic branching 4 - Reference: Pro Git, 2nd edition

Basic branching

Basic branching 5
Basic branching 5 - Reference: Pro Git, 2nd edition

Basic branching

Basic branching 6
Basic branching 6 - Reference: Pro Git, 2nd edition

The rebase feature

Interesting rebase 1
Interesting rebase 1 - Reference: Pro Git, 2nd edition

The rebase feature

Interesting rebase 2
Interesting rebase 2 - Reference: Pro Git, 2nd edition

The rebase feature

Interesting rebase 3
Interesting rebase 3 - Reference: Pro Git, 2nd edition

The rebase feature

Interesting rebase 4
Interesting rebase 4 - Reference: Pro Git, 2nd edition

The rebase feature

Interesting rebase 5
Interesting rebase 5 - Reference: Pro Git, 2nd edition

Different workflows

Centralised

Integration manager

Dictator and lieutenant

Centralised

Centralised workflow
Centralised workflow - Reference: Pro Git, 2nd edition

Integration manager

Integration-manager workflow
Integration-manager workflow - Reference: Pro Git, 2nd edition

Dictator and lieutenant

Dictator and lieutenant workflow
Dictator and lieutenant workflow - Reference: Pro Git, 2nd edition

Where to host your Git repositories?

Public clouds

Self-hosted servers

Public clouds

Examples: GitHub, Bitbucked

Git is not GitHub!

Generally free for public repositories

Self-hosted servers

Examples: GitLab, Gogs

Better choice if your work is confidential

Common features

Manage privileges

Pull requests / Merge requests

Issues

Wiki

Webhooks

Want to know more about Git?

Official documentation

Pro Git, 2nd edition

Cheat sheet

Videos