Git Educated About Git - 20 Essential Commands

Git Educated About Git - 20 Essential Commands

Git is a free, distributed version control system that is fast, easy to learn, and has great features like cheap local branching and convenient staging areas. It has also taken the open source world by storm, especially with the help of online services like GitHub. Learn 20 essential commands that will help you work with your next project, as well as common conventions and workflows.

EDIT: Updated 2/3/2014 for Sunshine PHP Conference.
EDIT: Updated on 9/15/2013 for Web & PHP Con. See the recording of "You're Doin' Git!" performance on YouTube: http://www.youtube.com/watch?v=gRWVIXRb0_Q

Ca57a7cfac69ba3abf517470f3770aae?s=128

Jeremy Lindblom

April 20, 2013
Tweet

Transcript

  1. git educated about git by Jeremy Lindblom ( @jeremeamia )

  2. git what? • why? • how?

  3. git

  4. hello! i'm jeremy.

  5. hello! i'm jeremy. PHP Software Engineer at Co-author of the

    AWS SDK for PHP Co-organizer of the Seattle PHP User Group Zend Education Advisory Board for 5.5 exam Keys/Vocals for Gigawattband.com @jeremeamia on and | webjeremy.com
  6. raise your hand if… 1.  You've used git. a.  …but

    only via a GUI. 2.  You've used SVN, CVS, P4, etc. 3.  You've never used a VCS. 4.  You have a GitHub account. a.  …and actually have repos you've created. 5.  You came to learn more about git. 6.  You just came to hear the song.
  7. git what is (g)it?

  8. what is git? 1. It's a version control system. 2.

    It's really popular. 3. It's distributed. 4. It's fast. 5. It's FOSS.
  9. what is git? 1. It's a version control system. 2.

    It's really popular. 3. It's distributed. 4. It's fast. 5. It's FOSS.
  10. version control •  Also source control or revision control • 

    “any practice that tracks and provides control over changes to source code”[1] •  Version Control System ( VCS ) – Git – SVN – CVS – Mercurial – Perforce – ClearCase – SourceSafe – Bazaar – TFS
  11. vocabulary – part 1 •  Repository | Repo – Set

    of current & past data about the files •  Revision | Version | Commit – A tracked change to the repo •  Working Copy – Local copy of the repo at a specific revision •  Head | Tip – The most recent revision
  12. vocabulary – part 2 •  Trunk | Mainline | Master

    – The main development path of the repo •  Branch – A divergent development path of the repo for features, fixes, etc. •  Merge – Integrate revisions from a branch back into trunk or other branch •  Tag – A name or label given to a revision
  13. snapshots, not deltas [2]

  14. what is git? 1. It's a version control system. 2.

    It's really popular. 3. It's distributed. 4. It's fast. 5. It's FOSS.
  15. who is using git?

  16. who is using git? https://github.com/aws

  17. who is using git? Zend Framework • Symfony • Laravel

    Doctrine • Guzzle • CodeIgniter • Monolog WordPress • CakePHP AWS SDK for PHP • Yii Composer • Magento PHPUnit • hhvm • Slim Drupal • FuelPHP • Kohana • Joomla Silex • PHPParser • Aura • Assetic • phpBB Phalcon • phpDocumentor • PyroCMS
  18. what is git? 1. It's a version control system. 2.

    It's really popular. 3. It's distributed. 4. It's fast. 5. It's FOSS.
  19. centralized version control [3]

  20. distributed version control [3]

  21. what is git? 1. It's a version control system. 2.

    It's really popular. 3. It's distributed. 4. It's fast. 5. It's FOSS.
  22. what is git? 1. It's a version control system. 2.

    It's really popular. 3. It's distributed. 4. It's fast. 5. It's FOSS.
  23. git why should you use (g)it?

  24. so you can… …continue being employable. …contribute to open source

    projects. …put code on your GitHub profile. …deploy code to PaaS solutions. …use Composer effectively. …ditch SVN, CVS, P4, etc.
  25. git how do you use (g)it?

  26. 20 essential commands 1.    git  help   2.  

     git  config   3.    git  init   4.    git  status   5.    git  add   6.    git  rm  -­‐-­‐cached   7.    git  commit   8.    git  diff   9.    git  reset   10.  git  log       11.  git  remote   12.  git  push   13.  git  clone 14.  git  pull   15.  git  fetch   16.  git  branch   17.  git  checkout   18.  git  merge   19.  git  tag   20.  git  push  -­‐-­‐tags  
  27. #1. git help $  git  help   usage:  git  [-­‐-­‐version]

     [-­‐-­‐exec-­‐path[=<path>]]  [-­‐-­‐html-­‐pat                        [-­‐p|-­‐-­‐paginate|-­‐-­‐no-­‐pager]  [-­‐-­‐no-­‐replace-­‐objec                        [-­‐-­‐git-­‐dir=<path>]  [-­‐-­‐work-­‐tree=<path>]  [-­‐-­‐nam                        [-­‐c  name=value]  [-­‐-­‐help]                        <command>  [<args>]     $  git  help  init                                                                     NAME                git-­‐config  -­‐  Get  and  set  repository  or  global  opti   SYNOPSIS                  git  config  [<file-­‐option>]  [type]  [-­‐z|-­‐-­‐null]  nam  
  28. #2. git config $  git  config  -­‐-­‐global  user.name  "Jeremy  Lindblom"

      $  git  config  -­‐-­‐global  user.email  myemailaddress@gmail.com     $  git  config  user.name   Jeremy  Lindblom   $  git  config  user.email   myemailaddress@gmail.com  
  29. #3. git init $  mkdir  git-­‐test   $  cd  git-­‐test

      $  ls  -­‐a   .        ..   $  git  init   Initialized  empty  Git  repository  in  ~/git-­‐test/.git/   $  ls  -­‐a   .        ..      .git   $  ls  -­‐a  .git   .                      HEAD                config            hooks              objects   ..                    branches        description  info                refs  
  30. #4. git status $  git  status   #  On  branch

     master   #   #  Initial  commit   #   nothing  to  commit  (create/copy  files  and  use  "git  add"  to   track)  
  31. making changes

  32. making changes <?php   echo  'Hello,  world!';   $  git

     status   #  On  branch  master   #  Initial  commit   #  Untracked  files:   #      (use  "git  add  <file>..."  to  include  in  commit)   #  README.md   #  index.php   nothing  added  to  commit  but  untracked  files  present  (use   "git  add"  to  track)   #  Git  Test     index.php README.md
  33. #5. git add $  git  add  index.php   $  git

     add  README.md     $  git  status   #  On  branch  master   #  Initial  commit   #  Changes  to  be  committed:   #      (use  "git  rm  -­‐-­‐cached  <file>..."  to  unstage)   #   #  new  file:      index.php   #  new  file:      README.md   #  
  34. #6. git rm --cached $  git  rm  -­‐-­‐cached  README.md  

    $  git  status   #  On  branch  master   #  Initial  commit   #  Changes  to  be  committed:   #      (use  "git  rm  -­‐-­‐cached  <file>..."  to  unstage)   #  new  file:      index.php   #   #  Untracked  files:   #      (use  "git  add  <file>..."  to  include  in  commit)   #  README.md  
  35. #7. git commit $  git  add  .   $  git

     commit  -­‐m  "Added  index  and  README"   [master  (root-­‐commit)  3ea3f8f]  Added  index  and  README    2  files  changed,  8  insertions(+),  0  deletions(-­‐)    create  mode  100644  README.md    create  mode  100644  index.php   $  git  status   #  On  branch  master   nothing  to  commit  (working  directory  clean)  
  36. #8. git diff $  git  diff   diff  -­‐-­‐git  a/README.md

     b/README.md   index  fdd135c..5152172  100644   -­‐-­‐-­‐  a/README.md   +++  b/README.md   @@  -­‐1,4  +1,4  @@    #  Git  Test       -­‐Testing  out  git.   +Testing  out  git.  It's  not  too  hard.  
  37. #9. git reset $  git  status   #  On  branch

     master   #  Changes  not  staged  for  commit:   #      (use  "git  add  <file>..."  to  update  for  commit)   #      (use  "git  checkout  -­‐-­‐  <file>..."  to  discard  changes)   #   #  modified:      README.md   #   no  changes  added  to  commit  (use  "git  add)     $  git  reset  -­‐-­‐hard   HEAD  is  now  at  fdd135c  Added  index  and  README  
  38. #10. git log $  git  log   fdd135cd6e09efd9c0b1b30387c2d555  Added  index

     and  README   0190a93b810f5084fa3a85afc54cf0d6  Initial  commit  
  39. we're still local! $  git  log   fdd135cd6e09efd9c0b1b30387c2d555  Added  index

     and  README   0190a93b810f5084fa3a85afc54cf0d6  Initial  commit  
  40. 20 essential commands 1.    git  help   2.  

     git  config   3.    git  init   4.    git  status   5.    git  add   6.    git  rm  -­‐-­‐cached   7.    git  commit   8.    git  diff   9.    git  reset   10.  git  log       11.  git  remote   12.  git  push   13.  git  clone 14.  git  pull   15.  git  fetch   16.  git  branch   17.  git  checkout   18.  git  merge   19.  git  tag   20.  git  push  -­‐-­‐tags  
  41. #11. git remote $  git  remote  add  origin  git@github.com:vendor/project.git  

    $  git  remote  -­‐-­‐verbose   origin  git@github.com:vendor/project.git  (fetch)   origin  git@github.com:vendor/project.git  (push)  
  42. workflow for changes Local

  43. #12. git push $  git  push  origin  master   Counting

     objects:  6,  done.   Delta  compression  using  up  to  4  threads.   Compressing  objects:  100%  (2/2),  done.   Writing  objects:  100%  (4/4),  432  bytes,  done.   Total  4  (delta  0),  reused  0  (delta  0)   To  git@github.com:vendor/project.git        0190a93..fdd135c    master  -­‐>  master  
  44. #13. git clone $  cd  ../   $  rm  -­‐rf

     git-­‐test/   $  git  clone  git@github.com:jeremeamia/git-­‐test.git   Cloning  into  'git-­‐test'...   remote:  Counting  objects:  9,  done.   remote:  Compressing  objects:  100%  (6/6),  done.   remote:  Total  9  (delta  1),  reused  4  (delta  0)   Receiving  objects:  100%  (9/9),  done.   Resolving  deltas:  100%  (1/1),  done.   $  cd  git-­‐test  
  45. #14. git pull $  git  pull  origin  master   From

     github.com:jeremeamia/git-­‐test    *  branch                        master          -­‐>  FETCH_HEAD   Current  branch  master  is  up  to  date.  
  46. #15. git fetch $  git  fetch  origin     git

     pull vs. git  fetch  
  47. #16. git branch $  git  branch  improve-­‐readme   $  git

     branch      improve-­‐readme   *  master  
  48. #17. git checkout $  git  checkout  improve-­‐readme   Switched  to

     branch  'improve-­‐readme'   $  git  branch   *  improve-­‐readme      master  
  49. #18. git merge $  vim  README.md     $  git

     add  .   $  git  commit  -­‐m  "Improved  the  README"   [improve-­‐readme  749305e]  Improved  the  README    1  files  changed,  2  insertions(+),  0  deletions(-­‐)   $  git  checkout  master   Switched  to  branch  'master'   $  git  merge  improve-­‐readme   Updating  fdd135c..749305e   Fast-­‐forward    README.md  |        2  ++    1  files  changed,  2  insertions(+),  0  deletions(-­‐)  
  50. #19. git tag $  git  tag  v1.0.0   $  git

     tag   v1.0.0   http://semver.org/  
  51. #20. git push --tags $  git  push  -­‐-­‐tags  origin  master

      Counting  objects:  5,  done.   Delta  compression  using  up  to  4  threads.   Compressing  objects:  100%  (3/3),  done.   Writing  objects:  100%  (3/3),  328  bytes,  done.   Total  3  (delta  1),  reused  0  (delta  0)   To  git@github.com:jeremeamia/git-­‐test.git        fdd135c..749305e    master  -­‐>  master    *  [new  tag]                  1.0.0  -­‐>  1.0.0  
  52. congratulations! 1.    git  help   2.    git  config

      3.    git  init   4.    git  status   5.    git  add   6.    git  rm  -­‐-­‐cached   7.    git  commit   8.    git  diff   9.    git  reset   10.  git  log       11.  git  remote   12.  git  push   13.  git  clone 14.  git  pull   15.  git  fetch   16.  git  branch   17.  git  checkout   18.  git  merge   19.  git  tag   20.  git  push  -­‐-­‐tags  
  53. commands summary Starting: Changing: Status: Syncing: Branching: Releasing: init,  clone,

     config   add,  commit,  status,  reset,  rm   push,  pull,  fetch,  remote   branch,  merge,  checkout   tag,  push  -­‐-­‐tags   status,  diff,  log  
  54. “You’re Doin’ Git!” By Jeremy Lindblom ♫ ♬   ♫

    ♫ ♬   ♬  
  55. git  help,  config,  and  init.     remote,  fetch,  pull,

     let's  edit.   diff,  add,  status,  commit.  you're  doin'  git.     log,  branch,  checkout,  that's  it!   checkout,  merge,  rebase,  don't  quit.   clean,  reset,  tag,  push  those  bits!  you're  doin'  git!     fork  and  clone  all  the  repos  you  know,   patches  and  pull  requests,  you'll  steal  the  git  show.   you're  doin'  git.  you're  doing  it!   check  git  blame  and  see  your  username.   hope  you  ran  the  tests  before  your  commit,   or  other  devs  will  think  you're  an  idiot.   you're  doin'  git.  (x4)     You're  Doin'  Git!   ©2013  Jeremy  Lindblom  
  56. git — tools —

  57. git hosting Third-party hosting •  GitHub •  Bitbucket •  SourceForge

    •  Gitorious •  Google Code •  CodePlex Self-hosting •  Git •  Gitolite •  Gitosis
  58. git guis •  git-gui + gitk •  GitHub (web /

    Mac / Windows) •  Tower •  GitBox •  SourceTree •  TortoiseGit •  Your IDE
  59. git — workflows —

  60. popular workflows •  git-flow – http://nvie.com/posts/a-successful-git- branching-model/ •  Github Flow

    – http://scottchacon.com/2011/08/31/ github-flow.html
  61. git-flow [4]

  62. multiple remotes AWS  SDK  for  PHP   AWS SDK for

    PHP
  63. custom workflows AWS SDK for PHP

  64. [5]

  65. github features •  Awesome web interface •  Encourages collaboration • 

    Issue and milestone trackers •  Wikis, project pages, organizations •  Comments and code reviews •  Forking and Pull Requests (PRs)
  66. git what? • why? • how?

  67. git why? how? what? A fast, distributed, fun, popular, &

    free VCS. To be employable & a good OSS contributor. Learn the CLI & tools. Create lots of branches.
  68. git educated about git by Jeremy Lindblom ( @jeremeamia )

    Thanks! Questions? Rate on Joind.in: https://joind.in/10519
  69. git tutorials •  http://try.github.io/ •  http://book.git-scm.com/ •  http://progit.org/book/ •  http://gitimmersion.com/

    •  http://githowto.com/ •  http://gitref.org/ •  http://gitready.com/
  70. references 1.  http://en.wikipedia.org/wiki/ Revision_control 2.  http://git-scm.com/book/ch1-3.html 3.  http://git-scm.com/book/en/Getting- Started-About-Version-Control 4. 

    http://nvie.com/posts/a-successful-git- branching-model/ 5.  https://github.com/aws/aws-sdk-php