Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Matt Gauger - Git & Github web414 December 2010

4,018 views

Published on

Slides from Matt Gauger's talk at the December 2010 Web414 on Git & Github

Published in: Technology

Matt Gauger - Git & Github web414 December 2010

  1. 1. Git &Github
  2. 2. Housekeeping•Slides & blog post will be available at: blog.mattgauger.com•Follow me: twitter.com/mathiasx•More resources at the end & linked in my blog post
  3. 3. Giving not just one talk,not two, but three talks in December!
  4. 4. MKE PHP User’s Group: PHP vs. Rails Dec 14th 6PM
  5. 5. MKE Ruby User’s Group:What’s new and great in Rails 3 Dec 20th 7PM
  6. 6. About Me
  7. 7. I am not an expert.
  8. 8. This talk is aimed at beginners.
  9. 9. So please do play along.
  10. 10. Introducing:A fictional user thathas never used git.
  11. 11. Get Stuff Done.
  12. 12. Github is the hook.
  13. 13. jQuery prototypescriptaculous mootoolsyui3
  14. 14. Ruby on Rails web.py &Symfony many othersDjango
  15. 15. But why is Github so popular?
  16. 16. Let’s take a look.
  17. 17. Github is popular becauseit optimizes for the things developers need to do
  18. 18. It doesn’t get in the way.
  19. 19. And because it’s fun.
  20. 20. Back to our user.
  21. 21. Found Heard on Pete’s blog.
  22. 22. The user wants to addgRaphaël graphs to Heard
  23. 23. Graphs are cool.
  24. 24. The user signs up for Github.
  25. 25. They go back and click “Watch”
  26. 26. Clicks “Fork”
  27. 27. And somethingmagical happens.
  28. 28. (Parents please make your children leave the room or cover their eyes during this part of the program.)
  29. 29. We now have ourown fork of Heard.
  30. 30. Forks are copies.
  31. 31. The first step in usingGithub after signing up is to install git (duh)
  32. 32. This is left as an exercise for the reader!
  33. 33. http://git-scm.com
  34. 34. Meanwhile, in ourAccount Settings
  35. 35. Sidenote:What are SSH keys and why do I need them?
  36. 36. SSH is a secure communicationsmethod that uses public/private key encryption.
  37. 37. You generate two keys:a public and a private key.
  38. 38. Github knows that only you have the private key
  39. 39. So every time we communicate with the Github server, we don’thave to type a password!
  40. 40. Generate a key pair
  41. 41. $ ssh-keygen
  42. 42. Generates id_rsaand id_rsa.pub inyour .ssh/ folder
  43. 43. The .pub file isthe public key
  44. 44. ssh-rsaAAAAB3NzaC1yc2EAAAABIwAAAQEAx5qfMKhR/+PQcOw2P/ho36T/aorbGJxiNwLDjrLenFK122nrdjdAKJtBVqCLd2Doagd0iEOFFhMhdJ8hNZ3depupx3JAiCswCBMsL4orjfX1suyR5DA5QyHpf5OGZdKacutlD3l/CsPq2IH2coQnwlnZTVo6oEBklweTHImx0ElfTaqdYOZZ+SW4NQ01aj+6jNb4g4D9BqcIcXA/XDL6B4fi6FtbJo4HlfjAt/YYOKhxblKYRvBuftfJ0Mrn4Nl1twY5tZ23gDG+4LZli7fdoFzRN3EjuEhD/Mg61D1JISQyHDsJQWbOnAdnV3wko8HV9F1D65wpYprHZqueI2xo4w== mathiasx@banshee.local
  45. 45. Copy this key and paste itinto your Github settings.
  46. 46. We’re now ready to hack!
  47. 47. Go back to ourfork of Heard
  48. 48. $ git clone git@github.com:mathias-presentation/Heard.gitCloning into Heard...remote: Counting objects: 22, done.remote: Compressing objects: 100% (22/22), done.remote: Total 22 (delta 7), reused 0 (delta 0)Unpacking objects: 100% (22/22), done.
  49. 49. $ git clone URI
  50. 50. Creates a local version ofthe project from the server
  51. 51. $ lsCHANGELOG config.php table-tracks.sqlLICENSE heardsync.php tracks.phpREADME init.php
  52. 52. Now we have the code
  53. 53. The user makes somechanges to the code.
  54. 54. User wants git to trackchanges to those files.
  55. 55. For our purposes, theuser finds this command:
  56. 56. $ git commit
  57. 57. $ git commit# On branch master# Changed but not updated:# (use "git add ..." to update what will be committed)# (use "git checkout -- ..." to discard changes in workingdirectory)## modified: config.php# modified: init.php# modified: tracks.php#no changes added to commit (use "git add" and/or "gitcommit -a")
  58. 58. Nothing happened.
  59. 59. “no changes added to commit”
  60. 60. Nothing happened?
  61. 61. (use "git add" and/or "git commit -a")
  62. 62. git add filename
  63. 63. git commit -a
  64. 64. The -a is for all
  65. 65. That is, commit everythingthat changed in the project.
  66. 66. The user types in
  67. 67. $ git commit -a
  68. 68. And is dropped into.. a text editor?
  69. 69. Default text editor.
  70. 70. Likely vim on Linux or Mac OSX.
  71. 71. To change it to something more user-friendly:
  72. 72. $ git config core.editor "nano"
  73. 73. The text editor is fora commit message.
  74. 74. Git is already tracking the exact changes to files.
  75. 75. Your commit messageshould be more abstract.
  76. 76. That boils down to
  77. 77. What did youactually do?
  78. 78. In one line or so.
  79. 79. A good commit messagewill help later when you’re trying to remember what you did.
  80. 80. So now we break the narrative.
  81. 81. Show a lot of things happening at once,remind everyone of whats going on!And with every shot show a littleimprovement,to show it all would take too long!Thats called a montage! MONTAGE!Ooh, we want a montage! MONTAGE!
  82. 82. A typical commit:
  83. 83. $ git commit -am "Added the gRaphael libraryto be loaded, but havent integrated it yet."[master 1a4014f] Added the gRaphael libraryto be loaded, but havent integrated it yet. 3 files changed, 3 insertions(+), 3 deletions(-)
  84. 84. We don’t have to commit all changes at once
  85. 85. [edit some files]$ git add config.php$ git add init.php$ git add filename
  86. 86. git status
  87. 87. $ git status# On branch master## Changes to be committed:# (use "git reset HEAD ..." to unstage)## modified: config.php# modified: init.php## Changed but not updated:# (use "git add ..." to update what will be committed)# (use "git checkout -- ..." to discard changes inworking directory)## modified: tracks.php#
  88. 88. Were only going to commit the changes in the config.php and init.php
  89. 89. $ git commit -m "A little refactoring."[master 6dd5c59] A little refactoring. 2 files changed, 2 insertions(+), 2 deletions(-)$ git status# On branch master## Changed but not updated:# (use "git add ..." to update what will be committed)# (use "git checkout -- ..." to discard changes inworking directory)## modified: tracks.php#no changes added to commit (use "git add" and/or"git commit -a")
  90. 90. Notice that tracks.php is still waiting to be committed.
  91. 91. The “staging area”
  92. 92. To see the history of our project, type:
  93. 93. $ git log
  94. 94. $ git logcommit e47cd6eb917d2a68ec6d1197a38faa1a1ff5e564Author: Matt Gauger <matt.gauger@gmail.com>Date: Thu Dec 9 14:27:04 2010 -0600 Add some newlines after error output.commit 4cce3dff9c8d03b7db1710f7addaa7d556921a44Author: raster <pete@rasterweb.net>Date: Sun Nov 14 11:38:50 2010 -0600 Minor changes, still learning git[truncated]
  95. 95. You may be asking
  96. 96. “How do I upload mychanges back to Github?”
  97. 97. $ git push
  98. 98. $ git pushCounting objects: 5, done.Delta compression using up to 4 threads.Compressing objects: 100% (3/3), done.Writing objects: 100% (3/3), 335 bytes, done.Total 3 (delta 2), reused 0 (delta 0)To git@github.com:mathias/Heard.git fb2cc2b..e47cd6e master -> master
  99. 99. And to get changes from the server:
  100. 100. $ git fetch
  101. 101. What happens if I screw up?
  102. 102. Throw away the changes
  103. 103. $ git reset --hard HEAD
  104. 104. Be careful with this, obviously
  105. 105. What if I only want to throwaway changes to one file?
  106. 106. $ git checkout -- init.php$ git checkout HEAD init.php
  107. 107. We’ve covered the most common commands.
  108. 108. Now what?
  109. 109. Our user sends a PullRequest back to Pete.
  110. 110. This asks Pete to merge in their changes.
  111. 111. Pete can use the Githubweb interface to merge those changes in.
  112. 112. Which means our user hascontributed back to Heard,as they originally intended.
  113. 113. What about GUI clients?
  114. 114. “The commandline is scary!”
  115. 115. Mac•Tower.app: http://www.git-tower.com/•Gitbox: http://www.gitboxapp.com/•GitX: http://gitx.frim.nl/
  116. 116. Linux•git cola: http://cola.tuxfamily.org/•gitk is included in git-core•giggle for diffs: http://live.gnome.org/giggle
  117. 117. This has been a very brief introduction to Git.
  118. 118. Come see me for freeGithub stickers after.
  119. 119. Thank you for your time.
  120. 120. Further Reading:• help.github.com•gitref.org•progit.org/book•www.gitready.com

×