Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Learning Git

7be7f45c8b9c235e2c3741a9a55e7ade?s=47 Rob Dumas
October 16, 2012

Learning Git

From a talk I gave to the Chicagoland Library Drupal Group.

7be7f45c8b9c235e2c3741a9a55e7ade?s=128

Rob Dumas

October 16, 2012
Tweet

Transcript

  1. version control

  2. rob dumas chicago public library @stray

  3. ✓why version control? ✓installing git ✓your first repository ✓branching &

    merging in this lecture:
  4. r2d.to/gitstart links

  5. we’re all victims of data loss; some of us just

    don’t know it…yet.
  6. BACKUPS ARE REALLY F**KING IMPORTANT photo credit: alexander muse (flic.kr/p/noL2K)

  7. snapshots

  8. snapshots

  9. 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
  10. version control

  11. version control change joel on software: “distributed version contol is

    here to say, baby” (r2d.to/QJw8lr)
  12. ✓ what files have changed ✓ who made those changes

    ✓ when the changes were made ✓ how those changed files differ ✓ why they were changed (hopefully) accountability
  13. wikipedia record of changes to articles over time

  14. git-scm.com

  15. what’s so GREAT about git?

  16. ✓ 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
  17. ✓ built for any size group ✓ encourages non-linear development

    ✓ complete local repositories git is local & distributed
  18. ✓ “deltas” for efficiency (binary files stored whole) ✓ cryptographically-authenticated

    history using SHA1 hashes ✓ commits are atomic git is fast & secure
  19. git is stable & popular

  20. installing git git-scm.com/downloads sudo apt-get install git brew install git

    (or yum) (requires xcode & homebrew)
  21. git-scm.com/downloads/guis baked right in other git gui apps textmate bundle

    netbeans xcode and more!
  22. for windows users peepcode.com/products/ meet-the-command-line

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

  24. ~/.gitconfig $  git  config  -­‐-­‐global  user.name   "Joe  User" $

     git  config  -­‐-­‐global  user.email   "juser@site.org"
  25. basic workflow create/ clone repository make changes commit changes stage

    changes 1 2 3 4
  26. photo credit: muy yum (flic.kr/p/7ByV6Y) stage work area git

  27. git basics

  28. creating a repository $  mkdir  myproject $  cd  myproject $

     git  init Initialized  empty  Git  repository   in  ~/myproject/.git/
  29. myproject/.git/ don’t touch these files!

  30. 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
  31. repo status (“clean”) $  git  status #  On  branch  master

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

    #  Untracked  files: #      (use  "git  add  <file>..."  to  include  in   what  will  be  committed) # #   myfile.html nothing  added  to  commit  but  untracked  files   present  (use  "git  add"  to  track)
  33. adding files $  git  add  myfile.html you have to add

    the files you’ve changed each time you commit!
  34. repo status (staged) $  git  status #  On  branch  master

    #  Changes  to  be  committed: #      (use  "git  reset  HEAD  <file>..."  to   unstage) # #   new  file:      myfile.html #
  35. 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
  36. other commands $  git  log $  git  diff  COMMIT_HASH $

     git  rm $  git  mv
  37. .gitignore nuclear-­‐launch-­‐codes.txt source/* *.temp put files, folders and patterns in

    this file to tell git to ignore them.
  38. branching & merging

  39. master

  40. master dev

  41. master dev

  42. creating a branch $  git  branch  awesome $  git  checkout

     awesome Switched  to  branch  'awesome'
  43. 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
  44. the ‘stache

  45. the stash $  git  stash $  git  stash  apply $

     git  stash  list $  git  stash  drop  STASH_ID
  46. v1.0 master dev tagging

  47. tagging $  git  tag  -­‐a  v1.0  -­‐m  "Product   release"

    $  git  tag  -­‐a  ronburgundy  -­‐m   "Brick  killed  a  guy  with  a   trident."
  48. distributed git

  49. push & pull $  git  push  origin  master $  git

     pull  origin  master
  50. git on the server ✓your own git server ✓github

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

  52. further reading

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

  54. Version Control with Git 2nd. Edition by Loeliger & McCullough

    © 2012 O’Reilly Media ISBN 978-1-4493-1638-9 r2d.to/oreillygitbook
  55. r2d.to/gitstart links

  56. thank you!