Hi, everyone.
Welcome to another edition of "YouTube Developers Live." My
name is Ikai Lan.
I'm a member of the YouTube Developer Relations team.
And in today's show, we are going to be
talking about GitHub.
Now, GitHub, if you haven't heard of it before, it's a way
for people to share open-source code and to
contribute to open source.
And as of very recently, we've moved our code samples, as
well as some of our open-source projects here at
YouTube, to GitHub.
So in today's show, we're going to go over what GitHub
is, a rough overview of what it looks like,
some basic Git commands.
This is not going to be a Git tutorial, but I'm going to
give you enough so that you can get started, as well as
some intro to some cool Git tools like Git
GUIs that we use.
And at the end, we're going to talk about how you can
contribute to our Git projects.
And one final note, which is, you know, how we like to end
the show, just a quick commercial at
the end of the show.
So with that, why don't we go ahead and get started?
Now, you may or may not have noticed--
we haven't really made a lot of noise around this, but
we've moved our API code samples to GitHub.
They would previously be hosted at code.google.com/
p/youtube-api-samples.
But now, it's much easier to find them by going to
github.com/youtube.
So if you browse to github.com/youtube, you'll see
that this is the home for all of our API samples and some of
our open source projects.
So most of our samples follow the naming convention of
yt-samples, and then the name of the project.
So in this case, you'll see that we have samples for Go,
JavaScript, Ruby, Python, and most of the major programming
languages that we support.
So why don't we go ahead and start looking at how we can
start working with GitHub.
Now, let's say that you want to get at the
GitHub samples for Java--
the YouTube API samples.
You'd go to this page-- again, that's github.com/youtube,
click on yt-samples-java, and you'll see that this is a
project that we've been contributing to.
So if you want to download this sample code, what you
would do is you would go over to the right-hand part of the
screen, and you'll see Download ZIP.
And what's nice about this is that you don't have to install
any clients.
You don't have to install Git.
You don't have to know anything about Git.
You just hit Download, and you should have code that can
work, that you can fork off of and start working on.
So that's really cool.
But let's rewind a little bit and talk about why Git?
Well, GitHub is where developers are.
GitHub has a really good model where you can create an Open
Source project, and people can use what's called forking to
create a copy of your project and contribute to that copy.
And people can recursively keep doing this.
They can keep forking the fork.
And what typically happens is you have a canonical copy of a
project up in Git.
Like in this case, it's just in the YouTube account under
yt-samples.java.
Someone might fork this, make some changes, and they would
send what's called a pull request to me.
A pull request is a way of saying, hey,
I've made some changes.
I want you to check these out.
And I can go through and say, do I want these changes or
not, and merge them in or not merge them in.
And I think that's really cool because if you think about the
old way in which you used to contribute to open source, you
used to have to send a patch, and it was really difficult.
And what's really nice about this way is that I've seen
some projects where a fork has actually overtaken the
canonical or main original project
and become more popular.
And that's perfectly fine because this is open source.
So more about Git, why I like Git a lot.
Git is fast, right?
And if you come from a world of SVN, or Subversion, you
know that Subversion is based on the idea that you have a
central repository, and you're copying from the repository,
whereas Git is more of a decentralized system.
So GitHub is a centralized system for a decentralized
SCM, Source Control Management tool.
But you can run Git without using GitHub.
And if GitHub goes down, you could have a backup server
that you push to, and you could do a lot
of really cool things.
So why don't we go ahead and do a quick
introduction to Git?
If you don't have Git installed, you can go ahead
and search for Git.
That's spelled G-I-T. And if you're using something like
Ubuntu, and you want to install the packages git-core.
So sudo apt-get git-core will get you the tools you need.
You can also download some packages that will make your
life easier.
I've downloaded this for Mac.
Now I've already done, this so I'm not going to go through
this process.
But here I am in a terminal.
I'm in a temp directory, so I can
basically trash this directory.
Now, I have Git already.
And if I hit Git, I'm going to get a bunch of commands.
So the first thing we're going to want to do if we want to
track the project, if we don't just want to download the zip
file, is we want to go to the GitHub page, right?
And we want to find the clone URL.
So right here, this is the clone URL, right here.
And I guess you can clone with Subversion, but typically
that's not something I commonly see.
So I'm going to go ahead and copy this to my clipboard.
Now I'm going to go back into Terminal.
I'm going to type, "Git clone." I'm going to paste the
repository in here, and there you go.
I've cloned the whole thing.
Now, that was pretty quick.
I have a fast network connection here, but I
guarantee you Git is really fast.
It's really, really cool stuff.
So if I go in here, I'll see that I have all the projects
for the Java sample code, and I can start running this on my
local machine.
We're using Maven nowadays, so is you have Maven, you can
start building this, running this, importing it into your
IDE, all that cool stuff.
Now, Git is very, very fast, like I mentioned.
And one of my favorite commands is to use a Git Log.
And a Git Log--
I'm going to pipe this into more so I can paginate it--
a Git Log tells me all the commits
that have been happening.
And it doesn't show me the code, but there is a verbose
mode so I can see all the different diffs of what I've
been doing in Git.
But hopefully, you won't need to be doing this too much if
you're just getting started.
And let's say we make an update to the repository.
Let's say we push some new code to fix bugs
or add a new feature.
What would you do?
Well, you would usually type, "git pull."
And this is going to check to see if you have the latest
version of code.
And I do have the latest version of code, and it
doesn't do anything.
So this is really cool, and you can start working with
things right away.
When you start to want to make changes, you want to learn
about git add as well as git commit.
And like I said, this is not going to be a
tutorial about Git.
One of the best books on Git is actually
free in open source.
It's over here.
Just search for "Git Book." And you can find this on the
main Git home page.
This is written by one of the founders of GitHub, and it's a
very, very good, detailed book.
But I can understand that sometimes you just might want
to get started much quicker.
So there are a couple of good Git quick starts on the web.
But over time, if you're getting into Git, I would
highly recommend reading this book only because there's a
lot of more advanced usages.
You want to learn about how branching works.
Branches are very, very cool.
Whereas in something like Subversion, you want to avoid
branching, and in Git you always want to be branching.
You always want to be merging.
With Git, since a lot of things are local, when I do a
check in, I don't need to be online to do a Git check in.
So you could be on a plane, you could be on a train, and
you could be writing code and just making small changes.
So that's all really cool stuff.
Now, I'm going to show you one more thing, which I think is
really cool.
I tend to like use command line, and I would highly
recommend you use the command line.
But Git has become so popular that Git has now integrated
with lots of the popular IDEs.
For instance, if I'm writing a project in IntelliJ, that has
Git integration, it'll tell me which lines
have I changed, right?
Like, which lines have I added since the last commit.
And in Git, it is a best practice to always be
committing, because commits are so fast and local that you
should be committing lots and lots of small atomic changes
before essentially merging back into master head, which
you could think of this as merging back into trunk.
This is something you do very common.
So Git doesn't map to other source controls, like
Subversion, one to one because the workflow is a little bit
different, but it's something you get used to.
So I tend to like the Command Line for doing pulls, doing
pushes, as well as doing commits.
I don't like using GUI tools for those things.
But I do like using GUI tools.
And when you go to Git home page, you'll see some of the
many GUI tools.
Many of these are free.
Some of these are paid.
And the one that is becoming really popular is called
GitHub for Mac.
Now, I've got this installed for you guys, and where I
really like to use GUI tools is for Git Log.
I can very quickly see what's different, I can scroll up and
down, and I can do this much more easily than
I can in the terminal.
So you'll see that green is stuff that we've added, and
we've just done an import, so most of the stuff is green.
But let's see, here are some changes.
Oh, what have we done?
Oh, there was a problem with the XML file.
We removed a line and we added a line.
I'm not sure what we did there.
I think we just deleted a space or converted tabs to
spaces, or something weird like that.
And what's also nice is branches.
And we haven't been doing much branching here, but the GUI
will very quickly visualize where you have branched, where
you have merged, and [INAUDIBLE] to diffs quickly.
So again, if you've never looked at Git, I highly
encourage you to do it.
It's a very, very cool system.
So that's a Git GUI.
That's a Git book.
So I just wanted to go ahead and introduce all of these
things to you.
And again, you don't need to know how to do this.
You can just go to github.com/youtube, click on
Project, and click on Download ZIP.
When we go back GitHub Project, you'll see that
mostly what's in here is sample code.
But we host the code for YouTube Direct, YouTube Direct
Lite in here, as well as some of
YouTube's open-source projects.
So this is where we will be committing our resources in
the future, and I encourage you to look here.
We will be starting to put pointers on code.google.com to
start pointing to our GitHub page.
So that's what I have for you guys today.
Hopefully I didn't take too much of your time.
And there's one last thing that I wanted to talk about,
which is I have an announcement to make.
And that announcement is that our team is hiring.
So if you're interested in joining Developer Relations,
come to developers.google.com/jobs.
Let me just verify that that's a working URL.
It would be really embarrassing if it weren't.
Yes, it is.
So go to our page, developers.google.com/jobs.
Again, my name is Ikai Lan.
Thank you guys for joining in for the show, and hope to see
you guys on GitHub soon.
Take care.