Locked lesson.
About this lesson
Quick reference
Github For Version Control
Github.com allows us to save our version controlled code on a third party website for safe keeping.
When to use
Any time you make significant changes to your code, you should save it using version control and git. Since git sits on your local development environment, it's a good idea to push your code to a third party for safe keeping in case your local environment ever crashes. We'll use github for that.
Instructions
Sign up for a free account at GitHub.com
Next, copy your C9 ssh key by issuing this command in the terminal:
- cat ~/.ssh/id_rsa.pub
Copy and paste the whole block of text from the terminal, then log into your github.com account and click the "setting" icon in the top right corner of the screen. Next, click the "SSH and GPG keys" link on the left side of the screen. Finally, click the "New SSH Key" button at the top of the screen.
Name your key anything you like, then paste the ssh key into the text box provided. Click the "Add SSH Key" button to save your key.
Next, we need to create a new repository. Click the "Your Profile" link at the top right of the screen. Next, click the "Repositories" link at the top of the screen, then the "New" button.
Name the repository anything you like (pinteresting) and click "Public" then click the "Create Repository" button.
Github.com will provide you with two commands to enter into your C9 development environment, that should look like this:
- git remote add origin git@github.com:username/ProjectName.git
- git push -u origin master
From then on, whenever you want to push code to github.com use these three commands from the terminal:
- git add .
- git commit -am 'commit message'
- git push
Hints & tips
- Github.com offers free public code repositories
- Github.com makes you pay to keep code private
- Once you connect to github.com once, you can push code from then on with the "git push" command
- You don't need to log into github.com every time you write code
- 00:03 In this video, we're gonna set up our GitHub account, and
- 00:07 push our code, our git repository, up to GitHub.
- 00:11 So just head over to GitHub.com.
- 00:13 And like I said, there's a couple of different ways to save your code.
- 00:17 GitHub is one, Bitbucket is another.
- 00:20 In the next video, I'll talk about Bitbucket.
- 00:22 In this video I'm talking about GitHub, and
- 00:24 GitHub is definitely the most popular source control thing online.
- 00:27 Everybody has a GitHub account, a lot of times if you're trying to get a job,
- 00:31 your boss, your potential employer will wanna look at your GitHub account,
- 00:35 it's sorta like a social network for coders.
- 00:37 And your potential employer will look through your account and see the different
- 00:41 code that you've worked on in the past, and it gives them an idea of what your
- 00:44 skills are and all that good stuff, so it's important to have a GitHub account.
- 00:48 The thing is, GitHub is free if you allow all your code to be public, right?
- 00:53 If you wanna keep your code private, you have to pay for that.
- 00:56 Bitbucket on the other hand, will allow you to keep your code private.
- 01:00 And you don't have to pay for that,
- 01:02 so, some people like that if they wanna keep their code private, for
- 01:05 us, we don't care that our code is public, so we're gonna go ahead and use GitHub.
- 01:08 Like I said, it's the most popular one out there.
- 01:11 It's a good idea for you to have an account, so go ahead and
- 01:13 sign up and then sign in.
- 01:16 Okay, so
- 01:17 we need to connect our Cloud 9 development environment to our GitHub account.
- 01:22 The first thing we need to do is to add our SSH keys.
- 01:25 And SSH is, it allows us to authenticate between these two accounts.
- 01:32 So if we come in here and click on Settings.
- 01:36 And look down here for SSH keys, I've already got a few listed but
- 01:40 to get your SSH key from Cloud9, come back to the terminal and type in this command.
- 01:48 Cat then a space and this little tilde sign
- 01:52 /.ssh/id_rsa.hub.
- 02:01 Hit Enter and you see all this gobbledygook here.
- 02:03 This is your SSH key.
- 02:05 What we wanna do is highlight all this.
- 02:08 Right-click and click Copy, then come back here and add a new SSH key.
- 02:15 You can type anything you want, C9, that's fine and then right-click here and
- 02:20 click Paste and it pastes in all this stuff, and then click this add SSH key.
- 02:25 So it's added that, so now we're good to go.
- 02:27 Now, all we need to do is create a new repository, and
- 02:30 any time you wanna push code, you're pushing it up to a repository.
- 02:33 So every project that you have will have its own repository, and
- 02:38 I'm gonna call this Pinteresting.
- 02:43 And like I said, it's public.
- 02:45 Anybody can see it.
- 02:47 If you click Private, then you have to actually put in your credit card,
- 02:50 we don't wanna do that, so click Create Repository.
- 02:53 Now, it's gonna give us a couple of instructions here.
- 02:56 And these are the two that we want.
- 02:58 So what we wanna do is highlight this, right-click and
- 03:03 Copy, or you can hit Ctrl+C on your keyboard, Cmd+C if you're on a Mac.
- 03:07 Come back here, come down here, let's clear this.
- 03:11 And Cmd+V to paste it back in and hit Enter.
- 03:16 Then come back here and grab the other one.
- 03:18 And we can say that we copy this, paste it.
- 03:24 So it's edit our SSH key, and now it's pushing up the code, and
- 03:28 that should've done the trick.
- 03:29 If we come here and click your profile and
- 03:33 repositories, so here's our Pinteresting we just created.
- 03:37 And if we take a look at this, it has all of these files, there's our gem file.
- 03:43 All of our files have been pushed up from Cloud 9.
- 03:47 And take a look at this, see this initial commit,
- 03:50 that's that message that we typed in in the last video.
- 03:55 See if I can scroll back, right here, when we did our git commit, and
- 03:59 we typed in initial commit.
- 04:01 That little message is what shows up here.
- 04:03 And if you wanna see something cool, we can.
- 04:07 We can do something like make a little change.
- 04:08 Let's open the read-me file and I'm just gonna copy all this and
- 04:15 type in this is my Pinteresting project, John Elder.
- 04:21 Now I'm gonna save this, and let's come down here.
- 04:26 Now let's save this code, and we're gonna use the same commands we did last time.
- 04:29 git add ., git commit -am
- 04:34 Now, let's create a different message, I'm gonna say 'Changed ReadMe File'.
- 04:41 Now to push this code from now on, we type in git push, and that's it.
- 04:47 And you can see it's doing its thing.
- 04:50 And it's, we only changed one file, so only one file got pushed.
- 04:56 But now if we go back to GitHub and click reload,
- 05:00 we see all these initial commits because none of these files changed, but
- 05:02 this README file, it has Changed Readme File, this is the new commit message.
- 05:07 And if we click on this, boom, it says, this is my Pinteresting project,
- 05:10 John Elder.
- 05:12 Just like it says right here.
- 05:13 So we're ready to go.
- 05:14 We've got git set up locally.
- 05:16 We've got GitHub set up in the Cloud here.
- 05:19 We can push our code to GitHub anytime we want by issuing those three commands we
- 05:23 just did, and in the next video I'll talk very quickly about BitBucket.
Lesson notes are only available for subscribers.