Slide 1

Slide 1 text

version control

Slide 2

Slide 2 text

rob dumas chicago public library @stray

Slide 3

Slide 3 text

✓why version control? ✓installing git ✓your first repository ✓branching & merging in this lecture:

Slide 4

Slide 4 text

r2d.to/gitstart links

Slide 5

Slide 5 text

we’re all victims of data loss; some of us just don’t know it…yet.

Slide 6

Slide 6 text

BACKUPS ARE REALLY F**KING IMPORTANT photo credit: alexander muse (flic.kr/p/noL2K)

Slide 7

Slide 7 text

snapshots

Slide 8

Slide 8 text

snapshots

Slide 9

Slide 9 text

1.0 2.0 3.0 4.0 5.0 developers work in teams and need to track the changes to their code over time

Slide 10

Slide 10 text

version control

Slide 11

Slide 11 text

version control change joel on software: “distributed version contol is here to say, baby” (r2d.to/QJw8lr)

Slide 12

Slide 12 text

✓ what files have changed ✓ who made those changes ✓ when the changes were made ✓ how those changed files differ ✓ why they were changed (hopefully) accountability

Slide 13

Slide 13 text

wikipedia record of changes to articles over time

Slide 14

Slide 14 text

git-scm.com

Slide 15

Slide 15 text

what’s so GREAT about git?

Slide 16

Slide 16 text

✓ no cost (“free as in beer”) ✓ gpl version 2 (“free as in speech”) gnu.org/licenses/gpl-2.0.html git is free & open source

Slide 17

Slide 17 text

✓ built for any size group ✓ encourages non-linear development ✓ complete local repositories git is local & distributed

Slide 18

Slide 18 text

✓ “deltas” for efficiency (binary files stored whole) ✓ cryptographically-authenticated history using SHA1 hashes ✓ commits are atomic git is fast & secure

Slide 19

Slide 19 text

git is stable & popular

Slide 20

Slide 20 text

installing git git-scm.com/downloads sudo apt-get install git brew install git (or yum) (requires xcode & homebrew)

Slide 21

Slide 21 text

git-scm.com/downloads/guis baked right in other git gui apps textmate bundle netbeans xcode and more!

Slide 22

Slide 22 text

for windows users peepcode.com/products/ meet-the-command-line

Slide 23

Slide 23 text

is git installed? $  git  -­‐-­‐version git  version  1.7.12.1

Slide 24

Slide 24 text

~/.gitconfig $  git  config  -­‐-­‐global  user.name   "Joe  User" $  git  config  -­‐-­‐global  user.email   "[email protected]"

Slide 25

Slide 25 text

basic workflow create/ clone repository make changes commit changes stage changes 1 2 3 4

Slide 26

Slide 26 text

photo credit: muy yum (flic.kr/p/7ByV6Y) stage work area git

Slide 27

Slide 27 text

git basics

Slide 28

Slide 28 text

creating a repository $  mkdir  myproject $  cd  myproject $  git  init Initialized  empty  Git  repository   in  ~/myproject/.git/

Slide 29

Slide 29 text

myproject/.git/ don’t touch these files!

Slide 30

Slide 30 text

cloning a repository $  git  clone  REPO_LOCATION Cloning  into  'myproject'... remote:  Counting  objects:  36,  done. remote:  Compressing  objects:  100%  (33/33),   done. remote:  Total  36  (delta  10),  reused  29   (delta  3) Receiving  objects:  100%  (36/36),  7.13  KiB,   done. Resolving  deltas:  100%  (10/10),  done. folder or URL

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

repo status (“dirty”) $  git  status #  On  branch  master #  Untracked  files: #      (use  "git  add  ..."  to  include  in   what  will  be  committed) # #   myfile.html nothing  added  to  commit  but  untracked  files   present  (use  "git  add"  to  track)

Slide 33

Slide 33 text

adding files $  git  add  myfile.html you have to add the files you’ve changed each time you commit!

Slide 34

Slide 34 text

repo status (staged) $  git  status #  On  branch  master #  Changes  to  be  committed: #      (use  "git  reset  HEAD  ..."  to   unstage) # #   new  file:      myfile.html #

Slide 35

Slide 35 text

committing changes $  git  commit  -­‐m  "Added  new  file,   myfile.html,  to  repo." [master  (root-­‐commit)  b80da17]  Added  new   file,  myfile.html,  to  repo.  0  files  changed  create  mode  100644  myfile.html

Slide 36

Slide 36 text

other commands $  git  log $  git  diff  COMMIT_HASH $  git  rm $  git  mv

Slide 37

Slide 37 text

.gitignore nuclear-­‐launch-­‐codes.txt source/* *.temp put files, folders and patterns in this file to tell git to ignore them.

Slide 38

Slide 38 text

branching & merging

Slide 39

Slide 39 text

master

Slide 40

Slide 40 text

master dev

Slide 41

Slide 41 text

master dev

Slide 42

Slide 42 text

creating a branch $  git  branch  awesome $  git  checkout  awesome Switched  to  branch  'awesome'

Slide 43

Slide 43 text

merging a branch $  git  checkout  master Switched  to  branch  'master' $  git  merge  awesome Updating  5bed678..217f575 Fast-­‐forward  myfile.txt  |  5  +++++  1  file  changed,  5  insertions(+)  create  mode  100644  myfile.txt

Slide 44

Slide 44 text

the ‘stache

Slide 45

Slide 45 text

the stash $  git  stash $  git  stash  apply $  git  stash  list $  git  stash  drop  STASH_ID

Slide 46

Slide 46 text

v1.0 master dev tagging

Slide 47

Slide 47 text

tagging $  git  tag  -­‐a  v1.0  -­‐m  "Product   release" $  git  tag  -­‐a  ronburgundy  -­‐m   "Brick  killed  a  guy  with  a   trident."

Slide 48

Slide 48 text

distributed git

Slide 49

Slide 49 text

push & pull $  git  push  origin  master $  git  pull  origin  master

Slide 50

Slide 50 text

git on the server ✓your own git server ✓github

Slide 51

Slide 51 text

github image source: the octodex (octodex.github.com)

Slide 52

Slide 52 text

further reading

Slide 53

Slide 53 text

get started with git alistapart.com/articles/get-started-with-git

Slide 54

Slide 54 text

Version Control with Git 2nd. Edition by Loeliger & McCullough © 2012 O’Reilly Media ISBN 978-1-4493-1638-9 r2d.to/oreillygitbook

Slide 55

Slide 55 text

r2d.to/gitstart links

Slide 56

Slide 56 text

thank you!