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!
68. $ 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 working
directory)
#
# modified: config.php
# modified: init.php
# modified: tracks.php
#
no changes added to commit (use "git add" and/or "git
commit -a")
92. Show a lot of things happening at once,
remind everyone of what's going on!
And with every shot show a little
improvement,
to show it all would take too long!
That's called a montage! MONTAGE!
Ooh, we want a montage! MONTAGE!
94. $ git commit -am "Added the gRaphael library
to be loaded, but haven't integrated it yet."
[master 1a4014f] Added the gRaphael library
to be loaded, but haven't integrated it yet.
3 files changed, 3 insertions(+), 3 deletions(-)
98. $ 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 in
working directory)
#
# modified: tracks.php
#
99. We're only going to commit
the changes in the
config.php and init.php
100. $ 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 in
working directory)
#
# modified: tracks.php
#
no changes added to commit (use "git add" and/or
"git commit -a")
My name is Matt Gauger. I’m a web app developer, Member of the Bucket Brigade. I work upstairs. I’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’t worry about its algorithms for storing changes.\nWe won’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’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
\n
so you see all those and you have to ask:\n
\n
\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
\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
\n
because they&#x2019;re beautiful\nand graphs are cool.\n
\n
\n
\n
\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
\n
\n
\n
As soon as you click the Fork button, you&#x2019;ll see:\n
\n
What&#x2019;s a fork?\n
Forks are copies of a project.\n
\n
\n
\n
\n
We will need to generate an SSH key and enter it into Github to get started.\n
\n
now, you don&#x2019;t really need to understand that part.\n
\n
\n
isn&#x2019;t the magic of cryptography awesome?\n
\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
\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
\n
\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
\n
\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
\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
\n
\n
\n
\n
\n
\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
\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
type this:\n
Now, why are we in a text editor? What it is for?\n
\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
\n
\n
\n
\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
\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
\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
\n
\n
at this point\n
\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
\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
\n
\n
\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
\n
we go back to github:\n
\n
\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
\n
\n
\n
\n
\n
\n
\n
\n
\n
if you&#x2019;d like to learn more about git, I highly recommend these sources\n