Git introduction

Preview:

DESCRIPTION

I was presenting an introduction to Git at Szegedtech

Citation preview

Git

Kornel Lugosi@Coornail

May 17, 2011

Table of contentsVersion control

Distributed revision control

Repository

Adding, commiting

Tracking changes

Branches

Pushing, pulling

Submodules

Ranges and other identifications of hashes

Other fun stuff

Resources

Version control

What?

Version control

Why?

Version control

Why?

◮ Backup

Version control

Why?

◮ Backup

◮ Revision handling

Version control

Why?

◮ Backup

◮ Revision handling

◮ Teamwork

Version control

Why?

◮ Backup

◮ Revision handling

◮ Teamwork

◮ Organized code commit access and workflow

Version control

Why?

◮ Backup

◮ Revision handling

◮ Teamwork

◮ Organized code commit access and workflow

◮ Deploying

Version control

How?

Version control

How?

◮ CVS

Version control

How?

◮ CVS

◮ SVN

Version control

How?

◮ CVS

◮ SVN

◮ Hg(Mercurial)

Version control

How?

◮ CVS

◮ SVN

◮ Hg(Mercurial)

◮ bzr (Bazaar)

Version control

How?

◮ CVS

◮ SVN

◮ Hg(Mercurial)

◮ bzr (Bazaar)

◮ ...

Version control

How?

◮ CVS

◮ SVN

◮ Hg(Mercurial)

◮ bzr (Bazaar)

◮ ...

◮ Git

Distributed revisioncontrol

Repository

(Repo)

Repository

$ git init

Repository

$ git init

$ git init --bare

Repository

$ git init

$ git init --bare

$ git init --bare --shared=group

Let’s put some code in!

$ echo "some code" > index.php$ git add index.php

Let’s put some code in!

$ echo "some code" > index.php$ git add index.php

Oh shit, it is only added to the “index“!

Let’s put some code in!

$ echo "some code" > index.php$ git add index.php

Oh shit, it is only added to the “index“!Well, fuck that!

$ git commit -m "My first commit"

Let’s put some code in!

$ echo "some code" > index.php$ git add index.php

Oh shit, it is only added to the “index“!Well, fuck that!

$ git commit -m "My first commit"

But it is not on the remote server yet!

$ git push ...

Nobody is looking, let’s commiteverything!

$ cat > index.php<?php

Thousand lines of code...ˆD$ git commit -a

What the hell did I do?

(in the working tree)$ git diff

What the hell did I do a year ago?

$ git log

I have no idea what I do

Let’s not show it toeveryone (yet)!

$ git branch experimental$ git checkout experimental

What branch am I on?

$ git branch -a

Turns out I am smart after all

$ git checkout master$ git merge experimental

I was smart today

Let’s show it to everyone$ git push <repository> <refspec>

I was smart today

Let’s show it to everyone$ git push <repository> <refspec>

Damn! Somebody was faster...Conflict =(

My code, let me show it to you!

$ git clone <repository>

My code, let me show it to you!

$ git clone <repository>

Okay, I already have you repo, I want to laugh atyour code!

boss$ git pull <repository>

Tagging

$ git tag

Submodules

Submodules

$ git submodule add <repository><path>

Submodules

$ git submodule add <repository><path>

From the root directory!

Ranges

$ git log 0af56ffa..HEAD

Ranges

$ git log 0af56ffa..HEAD

$ git diff v2.5..HEADˆ

Ranges

$ git log 0af56ffa..HEAD

$ git diff v2.5..HEADˆ

$ git cherry-pick HEAD˜4..

Other fun stuff

◮ $ git revert◮ $ git reset◮ $ git stash◮ $ git bisect◮ $ git rebase◮ $ git gc