How to Setup a Git Repository9:27 with Jim Hoskins
In this video, we create our git repository, and upload it to Github so we can both work on the project. We see how to create a new repository, create a commit, and get set up on Github.
[Master Class] [Designer and Developer Workflow] [Setting up the Git Repository] 0:00 So now, we have our Ruby on Rails application generated. 0:06 So, the next step I want to take is to go ahead and create the git repository 0:09 that we'll be working with. 0:14 Now, this master class is really more about the workflow. 0:16 This project is not something that Nick and I have already created 0:19 and are simply going over again. 0:22 We're doing this in real time, so you may see mistakes appear as we go along, 0:24 and you may see us just sort of go down the wrong path, but the beauty of this is 0:28 it's the development process, so we always have the opportunity to go back 0:32 and change something. 0:35 We're really not deploying the application, so we're really flexible in what we do. 0:37 So, let's go ahead and create the git repository. 0:42 So, I'm inside my easyjobs folder here. 0:45 I'll go ahead and do "git init." 0:48 And now we have a new git repository, and now I'll do "git add." 0:51 And if we take a look at our git status here, we can see we have all of our new files 0:57 added to it and even a git ignore file. 1:02 If we want to see what's in the default git ignore file that Rails created, 1:05 we can just open it up in TextMate. 1:09 And we can see that the default git ignore file for a Rails application 1:13 excludes the bundle directory, the database, the logs and the temp directory. 1:16 So, that looks pretty good for us. 1:21 So now, we want to go ahead and commit, but before we do that, I want to configure 1:24 my git so my name is attached to it and my email's attached when I commit. 1:28 So, the way we can do that is to type "git config" and we want to configure 1:34 the value "user.name," and I'll set it to Jim Hoskins. 1:40 This is going to set the name for our current project that we're in by default. 1:48 If we wanted to set up git to have a name for our computer in every project, 1:52 we could pass "--global," but this is a shared computer that we're using right now, 1:57 so I want to go ahead and just say this directory I'm going to go ahead and say 2:02 I only want to configure for this project. 2:06 So, I'm going to leave off the global that you would typically use. 2:09 And then I also want to configure the email address. 2:13 And I'll just put in my email address, and we are set up. 2:21 So now what I'm going to do is go ahead and commit, 2:30 and I'll just pass it the message of "Rails init." 2:34 So, we've created the first commit in our git repository, 2:41 and we can take a look at it just by typing "git log," and we can see that 2:45 my name and email address was attached properly to this commit, 2:49 which is good because there are going to be multiple people working on this project. 2:52 So, we want to make sure the information looks right. 2:56 So now, we want to set up our GitHub project. 3:02 The project is going to be hosted under the GitHub user Team Treehouse, 3:06 and this is going to be sort of the owner of our application, 3:09 and then we'll go ahead and set up Nick and myself as collaborators on this project 3:13 since we both have our own GitHub accounts. 3:17 So, let's go ahead and create a new repository. 3:20 I'm going to call it "Easy Jobs," and we'll say "The job board for the worlds easiest jobs." 3:23 We don't have a home page yet, and I'm going to mark this as private 3:39 so only Nick and I can work together on it. 3:44 Now, in order to create a private repository, you do need to pay for GitHub. 3:47 If you want to develop it as an open source project, you can use GitHub free. 3:51 So, let's go ahead and create the repository, and now it's giving us our empty project. 3:55 So now, it's going to give us some details on how to set up the remote origin 4:04 for GitHub so we can push to it, and what I'm going to do is 4:08 we've already done these steps, we're inside and we've initialized. 4:13 So, I'm just going to go ahead and select this line here. 4:17 This is going to add the remote of TeamTreehouseEasyJobs to our list 4:21 so we can push to it. 4:27 So, I'm just going to copy this, and if I paste it in and we run it, 4:29 if we take a look at git remote, we can see we now have a remote called origin, 4:33 which is hooked up to our GitHub. 4:39 Now, if we try to push it right now, it won't work. 4:41 So, let's try "git push origin master." 4:45 Now, we're going to verify the authenticity key for our first time, 4:49 and now we get a permission denied error, and this is because we haven't set up 4:55 our private key for this computer to interface with GitHub to authenticate us. 4:59 So, what I'm actually going to do is set up collaborators for Nick and myself 5:11 on the project, and then I'll create a key and add it to my personal account. 5:14 So, what I'm going to do is in my project here, I'm going to click on "admin." 5:19 And we have some information here, and let's click on "collaborators." 5:24 So, I'm going to add my GitHub account, which is Jim R. Hoskins. 5:28 And we'll go ahead and add Nick's as well. 5:33 Cool, so we're both set up. 5:38 Now, I'm actually going to log out of the Team Treehouse account, 5:40 and I'll log into mine. 5:43 So now, I'm logged in as Jim R. Hoskins, my personal account. 5:48 And we can see that I've been added to the private repository of teamtreehouse/easyjobs. 5:51 Now, this is a new computer for me to work on, so I do need to go ahead 5:57 and create my SSH key and add it to my personal list of keys 6:01 so when I use this computer, GitHub knows that it's me, 6:06 and that I'm authenticated to commit to easy jobs. 6:09 So, on our computer, we're going to go back to our terminal, 6:13 and I'm going to go ahead and create my key. 6:16 So, we can do this by using the program called "ssh-keygen," 6:20 and we'll do an rsa key by doing "-t rsa." 6:24 We'll associate it with the email Jim at Carsonified. 6:29 Let's go ahead and run this, and we're going to save it into our default location, 6:34 so I'll just click through enter, and let's enter a pass phrase 6:39 in order to protect our ssh key. 6:44 So, it's gone ahead and created our ssh keys, and we can see them in the 6:52 home/.ssh directory. 6:58 So, we have our id rsa which is our private key which we want to keep a secret. 7:02 And the id rsa.pub is the public key, and this is what we're going to give to GitHub 7:06 so we can identify that our private key is authenticated to work on GitHub. 7:13 So, let's actually open up our idrsa.pub. 7:20 So, we'll open up mate.home/.ssh/idrsa.pub. 7:23 So here, we can see this is the public key that we're going to be passing 7:32 to the GitHub page. 7:35 So, let's go back to GitHub. 7:38 We're signed in under my account, and we'll go to account settings, 7:40 ssh public keys, and add another public key. 7:44 And we'll go ahead and say our easy jobs machine. 7:51 And I'm going to go and copy all of this, and we'll paste it in. 7:58 And if we add the key, we can see we've now added it. 8:03 So now, our computer should be authenticated with GitHub to identify 8:07 that this computer is the user Jim R. Hoskins, and the user Jim R. Hoskins 8:11 is allowed to commit to the easy jobs repository. 8:16 So now, if we try to do "git push origin master," we should have 8:19 all the authentication we need to go ahead and push it. 8:24 Now, OS X has opened up a password dialog, and this is because 8:31 we have our ssh key protected by a pass phrase, 8:35 which I'm going to enter here to unlock it. 8:38 And let's go ahead and remember this so we don't have to keep typing it in every time. 8:41 And so now, we can see that the push has worked. 8:49 So, if we go back to the easy jobs page, 8:52 we can see that our commit has now shown up. 8:55 We see our first commit here for Rails init, and we can see everything's been pushed, 8:58 and we have a default Rails project. 9:03 So now, I'm going to go ahead and send a mesage saying that the project 9:06 is now in GitHub, and he can go ahead and set himself up and pull the project. 9:08 "Hey Nick, I set up the GitHub repository for our project." 9:14 "It's at TeamTreehouse/EasyJobs." 9:18 "So, I've added you as a collaborator, if you want to go ahead and pull it, 9:21 you can start working on it." 9:25
You need to sign up for Treehouse in order to download course files.Sign up