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

Learning Git

Rob Dumas
October 16, 2012

Learning Git

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

Rob Dumas

October 16, 2012
Tweet

More Decks by Rob Dumas

Other Decks in Technology

Transcript

  1. 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
  2. ✓ what files have changed ✓ who made those changes

    ✓ when the changes were made ✓ how those changed files differ ✓ why they were changed (hopefully) accountability
  3. ✓ 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
  4. ✓ built for any size group ✓ encourages non-linear development

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

    history using SHA1 hashes ✓ commits are atomic git is fast & secure
  6. creating a repository $  mkdir  myproject $  cd  myproject $

     git  init Initialized  empty  Git  repository   in  ~/myproject/.git/
  7. 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
  8. repo status (“clean”) $  git  status #  On  branch  master

    nothing  to  commit  (working  directory  clean)
  9. 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)
  10. adding files $  git  add  myfile.html you have to add

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

    #  Changes  to  be  committed: #      (use  "git  reset  HEAD  <file>..."  to   unstage) # #   new  file:      myfile.html #
  12. 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
  13. creating a branch $  git  branch  awesome $  git  checkout

     awesome Switched  to  branch  'awesome'
  14. 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
  15. the stash $  git  stash $  git  stash  apply $

     git  stash  list $  git  stash  drop  STASH_ID
  16. tagging $  git  tag  -­‐a  v1.0  -­‐m  "Product   release"

    $  git  tag  -­‐a  ronburgundy  -­‐m   "Brick  killed  a  guy  with  a   trident."
  17. Version Control with Git 2nd. Edition by Loeliger & McCullough

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