My name is Matt Gauger. I&#x2019;m a web app developer, Member of the Bucket Brigade. I work upstairs. I&#x2019;ve been using Git since at least the beginning of 2008 \nIf I go too fast or get too quiet, stop me and let me know. Thankyou!\nOk, so first off:\n
In the sense that I use git every day. I love it. But I don&#x2019;t worry about its algorithms for storing changes.\nWe won&#x2019;t go over the low level implementation of git or\ndiscuss the design decisions that make it fast, or any of that. Instead:\n
I&#x2019;ve included plenty of resources at the end to learn from.\n
Feel free to follow along on the websites I&#x2019;m looking at\nand sign up for things as we go along.\nNow, to set the stage, <announcer>imagine a world. A world where one man stands against the code.. </announcer> No. nothing like that.\n
I'm going to focus on a beginner user\nSomeone who has never contributed to open source\nThey&#x2019;re not trying to learn version control, \nbut they do want to contribute to an open source project\n
Like many of this, this fictional user just wants to get stuff done.\nSo, how do they find git?\n
It's likely that a person would run into git for the first time by visiting Github. This was not the case a year or two ago.\nThere are a lot of big, popular open source projects hosted there. \nToo many to list here, in fact, but here's a quick teaser:\n
so you see all those and you have to ask:\n
It certainly has a nice design. \nDesign alone doesn't necessarily attract developers\nMost of them still use the commandline with bitmap fonts\n
I'll put forward the theory that \nGithub is popular with developers because it optimizes for the things they need to do\n
It doesn&#x2019;t get in their way.\n
There&#x2019;s very little barrier of entry for a developer \nto contribute back to open source\nto upload new code\nor to find projects that interest them.\n
Let's assume our beginner has stumbled upon&#xA0;Pete's blog,\nand read the post about the Heard project\nwhich lets you mirror your Last.fm scrobbles and host it\n
The blog post contains a link to the Github repo, which looks like this:\n
This is the first time the user has been to Github, so they don't quite know how it works. If the user hovers over the Watch or Fork buttons, they will be instructed to sign in.\n
They might just click the big Download button and never come back, \nbut let's assume this person wants to hack on the project and contribute back to it.&#xA0;\n
because they&#x2019;re beautiful\nand graphs are cool.\n
But that doesn&#x2019;t seem to do anything except change the text from Watch to Unwatch.\n(They&#x2019;re following the project in their Dashboard to see changes, but our user doesn&#x2019;t\nknow that yet.)\n
As soon as you click the Fork button, you&#x2019;ll see:\n
What&#x2019;s a fork?\n
Forks are copies of a project.\n
We will need to generate an SSH key and enter it into Github to get started.\n
now, you don&#x2019;t really need to understand that part.\n
isn&#x2019;t the magic of cryptography awesome?\n
Our user runs the ssh-keygen command in their shell, after doing some research.\nThis will generate some files in .ssh/\nid_rsa and id_rsa.pub\n
which looks something like this:\n
The text is not important. \nJust remember it is a very unique string that helps Github identify you by your private key.\n
Now, the user is wondering, how do I get the code?\nThat big download button looks awfully enticing.\nBut that&#x2019;s not how you develop and contribute back with git, so let&#x2019;s assume our character knows this.\n
we can copy this URL to the clipboard.\nbut our user doesn&#x2019;t know what it does yet.\n
and if our user cd&#x2019;s (changes directory) into the newly created Heard directory:\n
If the user's SSH key was right, this will work. \nIf not, they'll have to go back and fix it. \nLooks like it worked, though, so we'll move on.\n
The git clone command created a directory named Heard in the user's home directory. \n
Our user makes some basic changes to the PHP files in their local Heard directory.\n
our user reasons that if git keeps tracks of versions of files, it will need to create a new version containing these changes. further, it will need to be told to track a given change, it doesn&#x2019;t do it automatically.\nGit tracks changes on an object level, not a file or project/directory level. \nYou don&#x2019;t need to understand that concept, but that means git is really smart about what changed and where.\n
The documentation says that the commit command is used to take a snapshot of the code in the current state. That sounds perfect. \nBut typing the command yields:\n
which, to me, after puzzling over it, looks like\n
which we could see in the line:\n
wait a second!\n
that&#x2019;s confusing. why doesn&#x2019;t git see the user&#x2019;s changes?\nluckily, git also includes a helpful pointer at the bottom there:\n
so now we have two more commands to use and figure out.\n
What is going on here? \nThere&#x2019;s very little instruction as to what to do.\nWhat is our user supposed to do with a text editor now?\n
now, vim isn&#x2019;t the most helpful or user-friendly text editor out there, if you don&#x2019;t know it.\nso, I&#x2019;m going to share with you a little spell from the wizards of old.\n
Now, why are we in a text editor? What it is for?\n
that is, git can already show us the files that changed.\nso when we do a commit, we want to leave a message about what we changed and maybe why.\n
than just listing off what files you changed.\n
I want to cover the commands that our fictional user will encounter while working on Heard.\nThis is the Keynote equivilent of a montage:\n
(that&#x2019;s the lyrics from a song on Team America: World Police, if you remember it.)\n
so, let&#x2019;s go do a typical commit and see what it looks like:\n
The git user in me wants to point out two things here:\nFirst, we&#x2019;re committing everything that changed.\nSecond, we&#x2019;re committing to the master branch, you can see it in brackets.\n
remember that git add command?\n
You'll notice there's no output from these commands. That's because nothing has changed yet. Those changes still need to be committed. It would probably be helpful at this point to have a look at what changed and what didn't. For that, we use the git status command.\n
when we run git status, the output will look like this:\n
you can see we added config.php and init.php with the git add command,\nso those are changes to be committed. Our change to tracks.php is not staged to commit yet.\n
after committing, we do another git status and see tracks.php is still there, modified but not staged, waiting to be committed too\n
This is a very important concept to grasp in git. Maybe you caught it in the last few slides.\nWhen we git add some files, they&#x2019;re added to a pending commit but not committed immediately. Files that aren&#x2019;t staged won&#x2019;t be a part of the commit. This is called the staging area.\n
next up, we want to take a look at the history of our project, that is, the changes that git has tracked.\n
at this point\n
In git, sending changes out to the server is called a push\na more complicated form of git push specifies the server to talk and the branch to use.\nfor our purposes, it will default to our master branch and to github.\n
the output here isn&#x2019;t important\nbut we can see it worked.\n
which again defaults to the default server, which is github.\nthis command will go out and ask github if there are any changes to the project, and pull them down if there are. This is useful if you have two computers and want to get your changes on say, your laptop, after developing on your desktop.\n
that is, what if I saved a file that I didn&#x2019;t mean to save, or I deleted a file I didn&#x2019;t mean to delete? Is git storing it somewhere for me? \nThe answer is Yes. What you want to do is:\n
the command to do that is:\n
which restores init.php to the HEAD state.\nThe HEAD state is just a useful placeholder name for the &#x201C;last commit&#x201D;\nGit has a lot of these placeholder names, learning them is worth it.\n
we go back to github:\n
because, again, the user&#x2019;s github project is a fork of Pete&#x2019;s github project. Pete needs to pull in the user&#x2019;s changes, that is, accept the pull request.\n
if you&#x2019;d like to learn more about git, I highly recommend these sources\n
1. Git &Github
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. Giving not just one talk,not two, but three talks in December!
4. MKE PHP User’s Group: PHP vs. Rails Dec 14th 6PM
5. MKE Ruby User’s Group:What’s new and great in Rails 3 Dec 20th 7PM
6. About Me
7. I am not an expert.
8. This talk is aimed at beginners.
9. So please do play along.
10. Introducing:A ﬁctional user thathas never used git.
11. Get Stuff Done.
12. Github is the hook.
13. jQuery prototypescriptaculous mootoolsyui3
14. Ruby on Rails web.py &Symfony many othersDjango
15. But why is Github so popular?
16. Let’s take a look.
17. Github is popular becauseit optimizes for the things developers need to do
18. It doesn’t get in the way.
19. And because it’s fun.
20. Back to our user.
21. Found Heard on Pete’s blog.
22. The user wants to addgRaphaël graphs to Heard
23. Graphs are cool.
24. The user signs up for Github.
25. They go back and click “Watch”
26. Clicks “Fork”
27. And somethingmagical happens.
28. (Parents please make your children leave the room or cover their eyes during this part of the program.)
29. We now have ourown fork of Heard.
30. Forks are copies.
31. The ﬁrst step in usingGithub after signing up is to install git (duh)
32. This is left as an exercise for the reader!
34. Meanwhile, in ourAccount Settings
35. Sidenote:What are SSH keys and why do I need them?
36. SSH is a secure communicationsmethod that uses public/private key encryption.
37. You generate two keys:a public and a private key.
38. Github knows that only you have the private key
39. So every time we communicate with the Github server, we don’thave to type a password!
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)## modiﬁed: conﬁg.php# modiﬁed: init.php# modiﬁed: tracks.php#no changes added to commit (use "git add" and/or "gitcommit -a")
58. Nothing happened.
59. “no changes added to commit”
60. Nothing happened?
61. (use "git add" and/or "git commit -a")
62. git add ﬁlename
63. git commit -a
64. The -a is for all
65. That is, commit everythingthat changed in the project.
66. The user types in
67. $ git commit -a
68. And is dropped into.. a text editor?
69. Default text editor.
70. Likely vim on Linux or Mac OSX.
71. To change it to something more user-friendly:
72. $ git conﬁg core.editor "nano"
73. The text editor is fora commit message.
74. Git is already tracking the exact changes to ﬁles.
75. Your commit messageshould be more abstract.
76. That boils down to
77. What did youactually do?
78. In one line or so.
79. A good commit messagewill help later when you’re trying to remember what you did.
80. So now we break the narrative.
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. A typical commit:
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 ﬁles changed, 3 insertions(+), 3 deletions(-)
87. $ git status# On branch master## Changes to be committed:# (use "git reset HEAD ..." to unstage)## modiﬁed: conﬁg.php# modiﬁed: init.php## Changed but not updated:# (use "git add ..." to update what will be committed)# (use "git checkout -- ..." to discard changes inworking directory)## modiﬁed: tracks.php#
88. Were only going to commit the changes in the conﬁg.php and init.php
89. $ git commit -m "A little refactoring."[master 6dd5c59] A little refactoring. 2 ﬁles 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)## modiﬁed: tracks.php#no changes added to commit (use "git add" and/or"git commit -a")
90. Notice that tracks.php is still waiting to be committed.
91. The “staging area”
92. To see the history of our project, type:
93. $ git log
94. $ git logcommit e47cd6eb917d2a68ec6d1197a38faa1a1ff5e564Author: Matt Gauger <email@example.com>Date: Thu Dec 9 14:27:04 2010 -0600 Add some newlines after error output.commit 4cce3dff9c8d03b7db1710f7addaa7d556921a44Author: raster <firstname.lastname@example.org>Date: Sun Nov 14 11:38:50 2010 -0600 Minor changes, still learning git[truncated]