Git workshop

fhLUG

Linux User Group FH Hagenberg

Reasons to Use Version Control

… and not to use them?

Glossary

Repository
Stores complete history, branches, tags (and other meta-information)
Working Copy
Your “playground”, actual source code
Commit / Revision
A specific, single version/snapshot
Branch
A distinct line of development

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 color.ui true
$ 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

What the fork?

$ git branch newbranch
$ git checkout newbranch

$ git branch
master
* newbranch

Merging changes

$ git merge newbranch

Resolving merge conflicts


$ git diff
diff --cc foo
…
<<<<<<< HEAD
current content
=======
branch content
>>>>>>> newbranch

$ vim foo
$ git add foo
$ git commit

Forking existing projects

$ git clone https://github.com/git/git.git git
$ cd git
…
$ git fetch
$ git merge origin/branch

Collaborating

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

$ git remote add repo https://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