Locked lesson.
About this lesson
How to backup your code and version control with Github.com
Exercise files
Download this lesson’s exercise file.
Using Github.com To Backup Our Code.docx57.5 KB
Quick reference
Using Github.com to Backup Code
Github is a website where you can backup your code.
When to use
You should use Github to backup all your code, always.
Instructions
Github.com is a free website that allows you to backup your code. Your code is public, if you want to keep it private you have to pay.
Every time you create a new coding project, you should create a repository for that code at Github.com
To show your SSH key to secure your account, type this command into your git bash terminal:
cat ~/.ssh/id_rsa.pub
Copy the SSH key and paste it into the SSH and GPG section of your Github.com account.
To push code to github.com after you have initialized it the first time, use this command:
git push
Hints & tips
- Github.com is a free code backup service.
- cat ~/.ssh/id_rsa.pub is the command to show your SSH key.
- 00:04 Okay, in the last video we talked about Git.
- 00:06 We set up version control locally.
- 00:08 Now we want to talk about github.com,
- 00:10 which is a website where we can push that local Git repository for safekeeping.
- 00:15 And why would you want to do this?
- 00:17 Well, your computer could crash.
- 00:18 It could melt, it could burn.
- 00:19 Your house could burn down.
- 00:21 Any number of things could happen.
- 00:23 So it's a good idea to push your code up to a third party website for safekeeping.
- 00:27 And GitHub is sort of the industry standard for that.
- 00:29 Head over to github.com, set up an account.
- 00:31 This is my account, github.com/flatplanet.
- 00:34 Might be a little button under here, if you go to this page, that says follow.
- 00:37 You can go ahead and follow me if you want.
- 00:39 You don't have to, no big deal.
- 00:41 Any time you create a new project,
- 00:43 what you need to do is create a new repository on github.com.
- 00:47 And the first time you do this, you have to upload something called SSH keys.
- 00:52 And that's a way to securely connect your local Git Bash terminal,
- 00:57 which is this guy, with github.com.
- 00:59 So what I did is, I went ahead and created a new instance of our terminal.
- 01:04 I just opened another one.
- 01:05 And if we type in pwd, we can see we're in /c/Users/flatplanet.
- 01:10 And yours won't say flatplanet.
- 01:11 Yours will say whatever your computer is called, or
- 01:14 what your logged in username is.
- 01:16 So what we need to do now is create a hidden directory to hold our SSH key.
- 01:20 So to do that, we just type in the mkdir command, stands for make directory.
- 01:24 And then type .ssh, the period makes it hidden.
- 01:28 Now we can change directory into .ssh.
- 01:31 And if we hit ls to list the stuff in here,
- 01:33 we see there's nothing in here at the moment.
- 01:35 So we'll go ahead and clear the screen.
- 01:38 Now we need to generate an SSH key.
- 01:40 So to do that, we tap in ssh-keygen.exe.
- 01:46 And it asks us where we want to save this key.
- 01:48 And just hit Enter, we want to save it right here.
- 01:51 Enter the passphrase, password, I'm just going to leave this blank.
- 01:54 You don't actually need to type in a password for this.
- 01:56 I recommend that you don't.
- 01:57 And it says do the same thing, so hit Enter again.
- 02:00 And boom, now it's been created.
- 02:01 So if we clear the screen, and now if we type in ls, we see these two files,
- 02:05 id_rsa and id_rsa.pub.
- 02:09 This is the one we want, the .pub, the public SSH key.
- 02:13 So to copy this to GitHub, we type in cat, and then id_rsa.pub.
- 02:20 And it's cataloged onto the screen.
- 02:22 So now we just highlight this whole big, gobbledygooky looking thing,
- 02:25 right-click and Copy.
- 02:27 Now head over to GitHub.
- 02:29 And in your account, click this little caret thing and go to Settings, and
- 02:33 then SSH and GPG keys.
- 02:35 And then just create a New SSH key.
- 02:38 I right-click and paste this in.
- 02:39 And you can call this anything you want.
- 02:41 You don't actually even have to give it a title.
- 02:44 So go ahead and click Add SSH key.
- 02:46 And it may ask you for your password for your github.com account.
- 02:50 Go ahead and type that in, and now you're good to go.
- 02:53 Next, head over to your profile.
- 02:54 And like I said,
- 02:56 anytime we create a new project, we need to create a new repository.
- 03:00 So click on Repositories, and create New.
- 03:04 And you can name this anything you want.
- 03:05 I'm just going to call it php-course2.
- 03:10 I've already got one called php-course, so we'll call this php-course2.
- 03:14 Now, it can be public or private.
- 03:16 And when it's public, anybody can see it.
- 03:18 And that's not a bad thing, especially if you're looking for a job.
- 03:20 A lot of employers will look at your GitHub account to look at your code,
- 03:23 to see what kind of skills you have.
- 03:25 But either way, public or private, they're both free.
- 03:28 So I'm just going to keep it public.
- 03:29 Now, Create repository.
- 03:31 Now there's two more steps we need to do in order to finish setting this up.
- 03:35 We need to push our existing repository from the command line.
- 03:39 So head back over here.
- 03:41 And we need to now change directory into the directory where our PHP code is
- 03:46 going to be.
- 03:46 cd, and that was in xampp/htdocs, and then php-course.
- 03:53 And okay, we can see this master branch, so we know we're in the right place.
- 03:57 If we type in ls, we can see the only thing in here is that index page.
- 04:01 All right, so clear the screen.
- 04:02 Head back over to GitHub.
- 04:04 And we need to type in these two commands into the terminal.
- 04:08 So I'm just going to Copy the first one and Paste it in.
- 04:13 I'm getting a command because I've already done this once in the past.
- 04:16 But you'll get a different thing, it'll say okay or whatever.
- 04:19 And then finally, the last thing we need to do is, git push -u origin master.
- 04:28 Are you sure you want to continue, yes.
- 04:31 Blah, blah, blah.
- 04:34 And we are good to go.
- 04:36 Now, we can confirm this by heading back to GitHub and
- 04:41 clicking on our profile, and then Repositories.
- 04:45 And we see this php-course2 is now there.
- 04:47 If we click on it, and we see our index.php file.
- 04:51 If we click on it, we could see, yep, there's our file.
- 04:55 Right, very cool.
- 04:57 Now, we can make a quick change.
- 04:58 Let's head over to our code here and type Hello World, how are you?
- 05:04 Save this.
- 05:04 Now let's go through the steps of pushing this code to GitHub from now on.
- 05:09 The same thing with our Git, we save this to Git, git add period.
- 05:13 And, git commit -am, and give it a message.
- 05:18 We 'tweaked index.php'.
- 05:23 Now, to push all of this to GitHub from now on, we type in git push, okay?
- 05:29 And we can come back here and click on here, and maybe hit reload.
- 05:34 And you can see here's the commit message we typed.
- 05:37 Remember, 'tweaked index.php'.
- 05:39 It's a nice way to keep track of things.
- 05:41 And if we click on this, sure enough, it says Hello World, how are you,
- 05:44 instead of just Hello World.
- 05:46 So we can see that it actually pushed up and everything's working correctly.
- 05:50 That's version control, we're not going to be using this a whole lot in this course.
- 05:53 But any coder should know how to save their code to Git and
- 05:57 push it up to GitHub.
- 05:59 And so now you know that, and you're ready to go.
- 06:02 In the next video, we're going to talk very quickly about Heroku for
- 06:05 third-party web hosting, to push our website that we're building,
- 06:09 our index page, up to professional Web hosting.
- 06:12 And that'll be in the next video.
Lesson notes are only available for subscribers.