Download - Git Introduction

Transcript
Page 1: Git Introduction

Git IntroductionFast Version Control

Page 2: Git Introduction

Who am I

•Gareth Hall

•Lead Developer and Hyundai New Zealand

•Director at Communica (http://communica.co.nz)

Page 3: Git Introduction

What is git?

•Git is a distribute version control system developed by Junio Hamano & Linus Torvalds.

•Git does not use a centralised server.

•Git runs on major operating system like OS X, Windows, Unix & Linux

Page 4: Git Introduction

Why it’s named git?

•Quoting Linus: “I’m egotistical, and I name all my projects after myself. First Linux, now git”

•Def: git - British slang for “pig headed, they are always correct , argumentative”

Page 5: Git Introduction

What does git do?

•Git tracks changes to content.

Page 6: Git Introduction

Advantages of git• Everything is local (almost)

• Fast

• Every clone / branch is a backup

• Work offline

• No single point of failure

• Lightweight

• Branching is cheap and merging is easy

• Many different workflows possible

• Distributed

• Every file and commit is checksummed

• Staging area

• Free and open source

Page 7: Git Introduction

Three States

Page 8: Git Introduction

Individual Workflow

Page 9: Git Introduction

Collaborative Workflow

Page 10: Git Introduction

Gitflow 1

Page 11: Git Introduction

Gitflow II

Page 12: Git Introduction

Basic CommandsSyntax: git <subcmd>

Page 13: Git Introduction

git init•Create an empty git repository or reinitialize an existing one

#:>git init

Initialized empty Git repository in /Users/garethhall/Sites/git_intro/.git/

Page 14: Git Introduction

git status• Show the working tree status

#:>git status

# On branch master

#

# Initial commit

#

# Untracked files:

# (use "git add <file>..." to include in what will be committed)

#

# includes/

# index.php

nothing added to commit but untracked files present (use "git add" to track)

Page 15: Git Introduction

git add

•Add file contents to the index

•git add .

•git add <filename> <filenname>

Page 16: Git Introduction

git status#:>git add .

#:>git status

# On branch master

#

# Initial commit

#

# Changes to be committed:

# (use "git rm --cached <file>..." to unstage)

#

# new file: includes/helpers.php

# new file: index.php

#

Page 17: Git Introduction

git commit•Record changes to the repository

#:>git commit -m "first commit"

[master (root-commit) 5f8a8d4] first commit

2 files changed, 48 insertions(+)

create mode 100644 includes/helpers.php

create mode 100644 index.php

Page 18: Git Introduction

git log•Show commit logs

#:>git log

commit 5f8a8d486ae1656b51194186c0dfb97ae1ec9835

Author: Gareth Hall <[email protected]>

Date: Sat Feb 16 14:43:40 2013 +1300

first commit

Page 19: Git Introduction

Edit files

Page 20: Git Introduction

#:>git status

# On branch master

# Changes not staged for commit:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

#

# modified: includes/helpers.php

# modified: index.php

#

no changes added to commit (use "git add" and/or "git commit -a")

Page 21: Git Introduction

#:>git add index.php

#:>git status

# On branch master

# Changes to be committed:

# (use "git reset HEAD <file>..." to unstage)

#

# modified: index.php

#

# Changes not staged for commit:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

#

# modified: includes/helpers.php

#

Page 22: Git Introduction

• #:>git commit -m "Changed output to table"

[master fffacb4] Changed output to table

1 file changed, 10 insertions(+), 2 deletions(-)

#:>git status

# On branch master

# Changes not staged for commit:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

#

# modified: includes/helpers.php

#

no changes added to commit (use "git add" and/or "git commit -a")

Page 23: Git Introduction

#:>git log

commit fffacb43627c5a44850b4b1543dc359f5d95edd6

Author: Gareth Hall <[email protected]>

Date: Sat Feb 16 16:10:45 2013 +1300

Changed output to table

commit 5f8a8d486ae1656b51194186c0dfb97ae1ec9835

Author: Gareth Hall <[email protected]>

Date: Sat Feb 16 14:43:40 2013 +1300

first commit

Page 24: Git Introduction

#:>git diff includes/helpers.phpdiff --git a/includes/helpers.php b/includes/helpers.phpindex 5c9a1fe..002256c 100644--- a/includes/helpers.php+++ b/includes/helpers.php@@ -1,5 +1,4 @@ <?php- /** * Pretty Print Helper * @@ -28,6 +27,12 @@ function dd($data, $die = false) { echo '<pre>'; var_dump($data);- echo '</pre>';- $die ? die() : null;-}\ No newline at end of file+ echo '</pre>';+ $die ? die() : null;+}++function logger($user_id, $message)+{+ $log_entry = $user_id . ',' . $message;+ return file_put_contents('log.log', $log_entry) ? true : false;+}

git diff

Page 25: Git Introduction

#:>git add .#:>git commit -m "Added logger"

[master 817dee6] Added logger 1 file changed, 9 insertions(+), 4 deletions(-)

#:>git log --oneline --decorate

817dee6 (HEAD, master) Added loggerfffacb4 Changed output to table5f8a8d4 first commit

Page 26: Git Introduction

git show• Show various types of objects

#:>git show fffacb4

commit fffacb43627c5a44850b4b1543dc359f5d95edd6Author: Gareth Hall <[email protected]>Date: Sat Feb 16 16:10:45 2013 +1300

Changed output to table

diff --git a/index.php b/index.phpindex f1f4a05..df11b0b 100644--- a/index.php+++ b/index.php@@ -10,6 +10,14 @@ if (($xml = @simplexml_load_file('https://www.bnz.co.nz/XMLFeed/portal/fcs/xml') } } -pp($bnz_rates, true);-+print '<table border="1">';+ print '<tr>';+ print '<th>Code</th><th>Rate</th>';+ print '</tr>';+ foreach ($bnz_rates as $code => $rate){+ print '<tr>';+ print '<th>' . $code . '</th><th>' . $rate . '</th>';+ print '</tr>';+ }+print '</table>';

Page 27: Git Introduction

git branch•List, create, or delete branches

#:>git branch outputHelper

#:>git branch

* master

outputHelper

Page 28: Git Introduction

git checkout•Checkout a branch or paths to the working tree

#:>git checkout outputHelper

Switched to branch 'outputHelper'

#:>git branch

master

* outputHelper

Page 29: Git Introduction

Develop new Feature

Page 30: Git Introduction

#:>git status

# On branch outputHelper

# Changes not staged for commit:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

#

# modified: includes/helpers.php

# modified: index.php

#

# Untracked files:

# (use "git add <file>..." to include in what will be committed)

#

# includes/.DS_Store

# includes/output_helper.php

no changes added to commit (use "git add" and/or "git commit -a")

Page 31: Git Introduction

#:>git add includes/helpers.php

#:>git commit -m 'Added doc block to logger function'

[outputHelper df78fc4] Added doc block to logger function

1 file changed, 8 insertions(+)

#:>git commit -a -m 'Refactored with new table output helper'

[outputHelper 51da4b7] Refactored with new table output helper

3 files changed, 38 insertions(+), 11 deletions(-)

create mode 100644 includes/.DS_Store

create mode 100644 includes/output_helper.php

Page 32: Git Introduction

#:>git log --oneline --decorate --graph

* 51da4b7 (HEAD, outputHelper) Refactored with new table output helper

* df78fc4 Added doc block to logger function

* 817dee6 (master) Added logger

* fffacb4 Changed output to table

* 5f8a8d4 first commit

#:>git checkout master

Switched to branch 'master'

#:>git log --oneline --decorate --graph

* 817dee6 (HEAD, master) Added logger

* fffacb4 Changed output to table

* 5f8a8d4 first commit

Page 33: Git Introduction

git merge• Join two or more development histories together

#:>git merge outputHelper

Updating 817dee6..51da4b7

Fast-forward

includes/.DS_Store | Bin 0 -> 6148 bytes

includes/helpers.php | 8 ++++++++

includes/output_helper.php | 36 ++++++++++++++++++++++++++++++++++++

index.php | 13 ++-----------

4 files changed, 46 insertions(+), 11 deletions(-)

create mode 100644 includes/.DS_Store

create mode 100644 includes/output_helper.php

Page 34: Git Introduction

#:>git log --oneline --decorate --graph

* 51da4b7 (HEAD, outputHelper, master) Refactored with new table output helper

* df78fc4 Added doc block to logger function

* 817dee6 Added logger

* fffacb4 Changed output to table

* 5f8a8d4 first commit

Page 35: Git Introduction

git reset

•Reset current HEAD to the specified state

Page 36: Git Introduction

git push

•Update remote refs along with associated objects

Page 37: Git Introduction

git fetch

•Download objects and refs from another repository

Page 38: Git Introduction

git merge

•Join two or more development histories together

Page 39: Git Introduction

git pull

•Fetch from and merge with another repository or a local branch

•fetch + merge

Page 40: Git Introduction

How in Drupal?

•Add all of Drupal to git

•Use the Features module to move configuration

•UUID Features to move content (alpha!)

Page 41: Git Introduction

Git Hosting Service

•Bitbucket (htt://bitbucket.org)

•Github (http://github.com)

•Run your own

•Gitosis

•Gitolite

Page 42: Git Introduction

Deployment

•Shell Access

•Continous Integration

•I don’t have shell access

•Setup your server as a remote

Page 43: Git Introduction

Deployment with shell

Page 44: Git Introduction

Continous Intergration

•Heroku (http://heroku.com)

•Pagoda (http://pagodabox.com)

•Bamboo (http://atlassian.com/software/bamboo)

Page 45: Git Introduction

I don’t have shell•Deploy (http://www.deployhq.com)

Page 46: Git Introduction

Server as Remote•Will need to use git hooks

Page 47: Git Introduction

Git Hooks

Page 48: Git Introduction

Git Hooks• #>vim post-receive

• #!/bin/sh

• cd ..

• GIT_DIR='.git'

• umask 002 && git reset --hard

Page 49: Git Introduction

Git GUI’s

Page 50: Git Introduction

Resources•Git (http://git-scm.com)

•Wiki (http://en.wikipedia.org/wiki/Git_(software))

•Git Essentials (https://tutsplus.com/course/git-essentials/)

•Change Management and Version Control (http://buildamodule.com)

Page 51: Git Introduction

Visual Version Control

Gource (http://code.google.com/p/gource/)

Page 52: Git Introduction

Questions


Top Related