Version Control Workshop

fhLUG

Linux User Group FH Hagenberg

Overview

Reasons to Use Version Control

When Not?

Glossary

Repository
Stores complete history, branches, tags
Working Copy
Your “playground”, actual source code
Commit / Revision
A single version
Branch
A separate line of development

Centralized Version Control

Distributed Version Control

Hands-On

Git, the information manager from hell

Git

Install & Setup

# apt-get install git gitk
$ git config --global user.name 'Daniel Knittl-Frank'
$ git config --global user.email 'S1010454…@students.fh-hagenberg.at'

$ git config --global core.autocrlf false

Creating repositories

$ cd path/to/project
$ git init

$ git init new_dir
$ cd new_dir

Adding files

$ >foo echo 'bar'
$ git add foo

Writing history

$ git commit
Initial commit for workshop

Here follows a longer description of what the commit did. In our case, we simply added a file for demonstration purposes.

Updating files

$ >>foo echo 'new content'
$ git add foo
$ git commit -m 'Updated file'

Browsing history

$ git log
commit 7d266f1981b3156784a17a44ef7b46a62c72a21c

Author: Daniel Knittl-Frank <S1010454…@students.fh-hagenberg.at>
Date:   Sun Feb 26 18:21:51 2012 +0100

    Updated file

commit 01d9322c973c5055ec630a7e9120ac90f6862269

Author: Daniel Knittl-Frank <S1010454…@students.fh-hagenberg.at>
Date:   Sun Feb 26 18:21:31 2012 +0100

    Initial commit for workshop
    
    Here follows a longer description …

Working Copy Status

$ git status
# On branch master
nothing to commit (working directory clean)

Inspecting changes

$ git diff
$ git diff HEAD^ HEAD
$ git diff branch1 branch2

Branching history

$ git branch newbranch
$ git checkout newbranch

$ git branch
  master
* newbranch

Merging changes

$ git merge newbranch

Resolving merge conflicts


$ cat foo
<<<<<<< HEAD
current content
=======
branch content
>>>>>>> newbranch

$ vim foo
$ git add foo
$ git commit

Forking existing projects

$ git clone git://git.kernel.org/pub/scm/git/git.git git
$ cd git
…
$ git fetch
$ git pull

Collaborating

$ git pull git://example.com/repo.git feature

$ git remote add repo git://example.com/repo.git
$ git pull repo feature

Publishing your projects

$ ssh user@server
$ git init --bare /path/to/repo
$ logout
$ git push user@server:/path/to/repo

Graphical Clients / Frontends