FREELessons: 24Length: 3.1 hours

Next lesson playing in 5 seconds

  • Overview
  • Transcript

5.1 Setting up Github

Github is probably one of the main reasons for Git’s incredible popularity: where else will you find hundreds or thousands of incredible projects, just waiting to be cloned? It’s important that you’re familiar with Github, so let’s set up an account!

5.1 Setting up Github

Everything we've done with git so far has involved a single repository on a single computer. However, there's a lot of power in git that's specifically created for interacting with other repositories, or other copies of the same repository in other computers. So that's what we're gonna be focusing on in the next couple of videos. I think it's pretty fair to say that the most common means of sharing git repositories these days is through GitHub, so that's what we're gonna focus on in this course. Of course, all of the actual git commands that we'll use on the command line, all of those git commands would be the same if you were using a different hosted git service, or if you were even running git on your own server. However, we are going to focus on GitHub because it's extremely popular, and it's a great example. So, of course we're going to have to start by opening up Google Chrome here, and we're gonna to head over to As you can see, they've got the normal marketing, promotional stuff on the front page here. For our first step we are going to click right here, Plans, Pricing and Signup. So what we wanna do is create an actual GitHub account. Now, you can actually have many different levels of paid GitHub accounts, however we're just gonna go with the free account because it gives us unlimited public repositories and unlimited public collaborators, and so therefore we don't really need anything more at this time. If you want to use git and GitHub to hold some private code that can't be seen by the outside would but you want to share that with other people and allow them to work on that project, then you'll want to consider one of these plans here, Micro, Small or Medium. And then of course if you are having a team or something bigger, you'll want to use one of their business plans. But for now, right here, create a free account. We've got to give it the standard stuff here and for a username, I'll just use the name of the user I'm on on this computer right now, sherlockTuts, there we go. All right, so there we go, we'll create the account and we have a little GitHub boot camp here. I'm gonna close this right here. So if you see, over here on the side, we have this Welcome to GitHub, What's Next section, and it tells us the first thing we might want to do is create a repository. Okay, so there are a couple of ways. We can either click the create a repository button over here, but this is gonna be your news feed of things that are going on between you and other people you're following on GitHub, so later on this link won't be here. But normally, if you come over to this side right over here, you'll have a new repository link. So I'm going to click that new repository link. Okay, so now we have to give it a repository name. And we're gonna call it project, just because that is the name of the project that we've been working on. For a description, I'll just say a fake project that's part of the Git Essentials course at Tuts+ Premium. This of course has to be a public account, because we don't have the ability to do private accounts. We're not gonna ask it to initialize this repository, cuz the repository's already created, so we're gonna click create repository. And you might think, well we already have a repository on our own computer, why are we creating one? Well, this is just creating a repository on the GitHub site. Now, this next stage is important here. GitHub gives us a list of next steps depending on whether we have an existing git repository or whether we are starting from scratch. So if you're starting from scratch, you can see these are the next steps you're told. We wanna make the project directory, move into it, create some content, and the important line, right down here, is git remote add origin, with this link after it. And we're gonna dive more deeply into what a remote is and how those work in a future video. However, as you can see down here, we already have an existing repository, so it tells us just cd into that repository and then add a remote and push it. Of course you're not gonna understand what these terms mean just yet, but we're gonna get to that in future videos. I'm gonna do this, however, right now. So we're going to pop open our terminal, we're going to cd into our project. Now, it's important here, you'll notice back at the top here we have some git setup, and we've already set up our user name and user email. However, the user email I'm using is not this email address. If I do get config, I have my normal email address. So what I actually want to do is set this at the local level, so I can run get config --local. Or, if I leave --local off since I am inside a git repository right now, as you know from an earlier screencast, it will just set it at the local level. I can say and I wanna set it to that. Now we can make sure that has been set by catting out in the current folder in our .git/config, and you can see right down here, user email is that. But of course, since it cascades from above, git config user .name is still set to Andrew Burgess, because that's cascading down from our global level config file, which is in our user directory. Right now I'm just gonna copy this line here, copy that, paste it in there, and I'm just gonna copy this, we'll come back to what this means later, paste that in there. And when we use this git push command that we're gonna talk about later, we're actually trying to connect to the GitHub servers. The authenticity of the host GitHub dot com can't be established, are you sure you want to continue connecting? If we say yes, notice that the connection was closed. The remote hung up unexpectedly, and this is because we don't currently have the ability to connect to our own user account on the GitHub servers because if we could do it with no setup, as we've just tried to do, then anyone could connect to our account and act as us. So what we have to do is come back here to GitHub. We actually have to set up some SSH configuration to be able to talk to GitHub properly. Now if you're not familiar with how SSH works, here's a link to a tutorial that was recently published on NetTuts that will give you a good understanding of what SSH is and how the basics of it work. I'm going to assume right now that you're familiar with SSH and how it works, and we're just gonna move ahead with that assumption. I'm going to go right up here to the account settings, and this is the account settings, and I recommend you browse through these. Most of this is GitHub specific stuff which isn't going to make too big of a difference to how you actually use GitHub in connection with git. So we're not going to discuss most of these things, but as you can see you can fill out your public profile here to give people a better idea of who you are. Under account settings, you can change your password, change your username, or delete your account. Under Emails, you can have multiple email addresses. Notifications Center, for all the different types of notifications you might receive from GitHub when different people are collaborating on your projects, what do you want to be emailed for. Billing and Payment History of course are only interesting if you actually have a paid account. Down here, SSH keys, that's where we wanna be. As you can see, we have no SSH keys, so we can't access our account from our terminal yet. And of course we're going to want to add an SSH key, but what do we put in here? What we have to do is come here to our terminal, and we actually have to create an SSH key. I'm going to open up a new tab. And now we have to actually create our SSH keys. Now, since we're on a Mac we can just do this in the normal terminal. If you're on Windows and you did not decide to install the UNIX tools in a way that you could actually use them from the normal command line in Windows, you're gonna have to open up a git BASH specifically, instead of just a normal Windows command line. However, once you've got the right terminal open, we're gonna wanna run the ssh-keygen command. However, before we get there, we have to see do we already have some keys. So I am going to try to cd into, in the home folder, there should be a .ssh folder. And as you can see I'm inside that and if I list it, I have the known host file. So this was just created when I tried to connect to GitHub right back here. As you can see, we have this message, we permanently added GitHub to our list of known hosts. However, I'm just going to remove this known hosts file just to keep things clean. It will be recreated shortly, but that's okay. And now, we're ready to create our keys. Now, of course you don't have to be inside the SSH folder to create the keys, as you'll see, but we're gonna be there anyway just cuz we are gonna want to show the keys right after this. So I'm gonna run ssh-keygen, then we wanna use -t and say rsa, this is the type of key that we're gonna use, and then -C and after this we wanna buy a comment. And in their SSH setup instructions, which you can read right here, their guide to setting up GitHub and SSH, they recommend using your email address. So I'll say Andrew dot com, and I'll hit enter. All right, so enter the file in which we want to save the key. By default, they choose user directory .ssh/id_rsa. That's good, so we'll just hit enter. So, now we need a passphrase, and it's important that you do add a passphrase. It adds an extra level of security to your GitHub account, and so I'm going to right now, just passphrase. I will write the same pass phrase again. All right, so our identification's been saved. Public key has been saved, etc., etc. So now all of that has been created. So now, if I clear the screen here and I list the files in this folder, you can see that we have the id_rsa file, and this is our private key, and then over here we have the id_rsa .pub file, and that's the public key. All right, and so it's that public key that we want to give to Git Hub. So I'm going to cat out right there, and that is the key. And what we wanna do is just copy this content right here, and we wanna paste it in here to the key. So now that I have that on my clipboard, I'm gonna come back, gonna paste it in there, now I'm gonna give it a title. I'll just say, just so I know which computer this is from, and I'm gonna add the key, and I'm gonna have to verify this with my password. And now that I've confirmed my password, you can see right here I have my SSH key, exactly as we had it before. So now to make sure this works, I can actually do ssh -T And now, if I hit Enter, you can see that again we're asked if we want to connect. I'll say yes, and now this is where I have to enter the passphrase that I entered on the terminal when I was creating my SSH key. Of course, you don't want to have to type in this password every time you're trying to connect to GitHub because if you do that a lot, that will get tedious. So there's a neat little tool that's called ssh-agent, and this can save your password securely so that you don't have to enter it every time. Since I'm on Mac OS X, this SSH agent is actually integrated with the key chain, as you can see here. So I can choose remember password in my key chain, and I'll never have to think about it ever again, and that's exactly what I do. On Windows, you can also run ssh-agent, since it was installed with the msysGit package we installed. And right down here, you can see a link to GitHub's ssh key passphrases help documentation, which will give you a little script that you can copy and paste into your .profile or your .bash or C file, and this will startup the ssh agent when you run your computer. For now, I'm going to put in that password and click okay. And you can see right here that the identity was added, and the connection was closed, so let me try that again. And the connection was closed because I took a little too long to explain that there, but if I run this again, now you can see we get the message Hi sherlockTuts! You've successfully authenticated, but GitHub does not provide shell access. So you can see here it does call us sherlockTuts. The only way that GitHub actually knew we were the sherlockTuts user account is because the SSH key that we used right here associated our computer with our account. So now if i close this window and come back here and try again to do that git push that we did before, which will be discussing in the next video, you can see that, give it a second, and our repository was pushed up to GitHub. So now if i come back here, come back to my main project page, you can see right here on my dashboard I do have indeed the project page. I click on that, and now you can see right here on GitHub all that content that we had been creating before on our computer is now showing up right here on GitHub. So in the next video, we're gonna look around that GitHub repository webpage, and check out the different view GitHub gives us for seeing that information. And then we'll go on to looking at how we can actually interact with GitHub as we move our code back and forth across the network.

Back to the top