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

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

Jeremy Lindblom

April 20, 2013
Tweet

More Decks by Jeremy Lindblom

Other Decks in Programming

Transcript

  1. git

  2. 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
  3. 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.
  4. 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.
  5. 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.
  6. 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
  7. 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
  8. 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
  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. 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
  11. 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.
  12. 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.
  13. 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.
  14. 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.
  15. 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  
  16. #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  
  17. #2. git config $  git  config  -­‐-­‐global  user.name  "Jeremy  Lindblom"

      $  git  config  -­‐-­‐global  user.email  [email protected]     $  git  config  user.name   Jeremy  Lindblom   $  git  config  user.email   [email protected]  
  18. #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  
  19. #4. git status $  git  status   #  On  branch

     master   #   #  Initial  commit   #   nothing  to  commit  (create/copy  files  and  use  "git  add"  to   track)  
  20. 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
  21. #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   #  
  22. #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  
  23. #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)  
  24. #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.  
  25. #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  
  26. #10. git log $  git  log   fdd135cd6e09efd9c0b1b30387c2d555  Added  index

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

     and  README   0190a93b810f5084fa3a85afc54cf0d6  Initial  commit  
  28. 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  
  29. #11. git remote $  git  remote  add  origin  [email protected]:vendor/project.git  

    $  git  remote  -­‐-­‐verbose   origin  [email protected]:vendor/project.git  (fetch)   origin  [email protected]:vendor/project.git  (push)  
  30. #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  [email protected]:vendor/project.git        0190a93..fdd135c    master  -­‐>  master  
  31. #13. git clone $  cd  ../   $  rm  -­‐rf

     git-­‐test/   $  git  clone  [email protected]: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  
  32. #14. git pull $  git  pull  origin  master   From

     github.com:jeremeamia/git-­‐test    *  branch                        master          -­‐>  FETCH_HEAD   Current  branch  master  is  up  to  date.  
  33. #16. git branch $  git  branch  improve-­‐readme   $  git

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

     branch  'improve-­‐readme'   $  git  branch   *  improve-­‐readme      master  
  35. #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(-­‐)  
  36. #19. git tag $  git  tag  v1.0.0   $  git

     tag   v1.0.0   http://semver.org/  
  37. #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  [email protected]:jeremeamia/git-­‐test.git        fdd135c..749305e    master  -­‐>  master    *  [new  tag]                  1.0.0  -­‐>  1.0.0  
  38. 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  
  39. 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  
  40. 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  
  41. git hosting Third-party hosting •  GitHub •  Bitbucket •  SourceForge

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

    Mac / Windows) •  Tower •  GitBox •  SourceTree •  TortoiseGit •  Your IDE
  43. [5]

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

    Issue and milestone trackers •  Wikis, project pages, organizations •  Comments and code reviews •  Forking and Pull Requests (PRs)
  45. 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.
  46. git educated about git by Jeremy Lindblom ( @jeremeamia )

    Thanks! Questions? Rate on Joind.in: https://joind.in/10519