- HD
- 720p
- 540p
- 360p
- 0.50x
- 0.75x
- 1.00x
- 1.25x
- 1.50x
- 1.75x
- 2.00x
We hope you enjoyed this lesson.
Cool lesson, huh? Share it with your friends
About this lesson
Git allows us to backup and maintain versions of our code. In this lesson, we'll learn how to push our code to Git.
Exercise files
Download this lesson’s related exercise files.
Push Our Code to Github57.5 KB Push Our Code to Github - Solution
55.9 KB
Quick reference
Push Our Code to Github
Github.com allows us to host our Django project code on their website for safekeeping and backup.
When to use
You should always use github to backup your code.
Instructions
Sign up for a free github account.
Log in, go to settings, then go to SSH and GPG keys. Click "Add Key" to add your key.
To get your ssh key, from your terminal use this command:
cat ~/.ssh/id_rsa.pub
Copy the key and paste it into github.com
Next, click on repositories and Create a new Repository. Grab the two commands that github gives you and enter them (one at a time) into your terminal.
Hints & tips
- Don't forget to add your ssh key to github.com!
- 00:04 Okay, in the last video, we set up version control.
- 00:05 In this video, we want to set up GitHub.
- 00:07 And github.com is a website that allows free git repository hosting.
- 00:11 And it's super popular with coders, it's almost like a little social network,
- 00:16 you can see I've gone to github.com and logged in.
- 00:20 And, if you click on your profile, this is what it looks like.
- 00:23 If you don't have an account here, go ahead and sign up for one,
- 00:27 it's completely free and it's really cool.
- 00:30 So, to use this, and why this is important is,
- 00:33 right now we saved our code to get with version control locally.
- 00:37 But computers can break down.
- 00:39 Computers can blow up.
- 00:40 I've had computers melt, right?
- 00:42 I've lost all my data before, it's always a good idea to keep your code
- 00:46 somewhere else, especially up in the cloud somewhere for safekeeping.
- 00:50 And that's what GitHub allows us to do.
- 00:51 It's also cool if you're trying to get a job, because your potential new boss can
- 00:56 come to your GitHub account and look at your code.
- 00:58 This is all public.
- 00:59 You can make it private if you want, but I recommend you just keep it public.
- 01:04 Nobody's going to steal your code.
- 01:05 If you've got some top secret startup you're working on, then sure,
- 01:08 make it private.
- 01:09 But for everything else, just keep it public.
- 01:12 That way, potential new employers can look at your code,
- 01:15 they can see, she knows how to do this, this, and this.
- 01:17 This is the code she's written.
- 01:20 We can see that and it's really cool.
- 01:21 So, once you've signed up and logged in, head over to,
- 01:25 I just clicked on this little carrot over here and go to Settings.
- 01:30 And then click on SSH and GPG keys,
- 01:31 we need to add that SSH key that we created a couple of videos ago.
- 01:35 So let's head back over to our terminal.
- 01:38 And let's just catalog out that SSH key.
- 01:42 So it was at ~/.ssh id_rsa.pub.
- 01:48 So hit Enter, and then just highlight all of this.
- 01:53 I'm just clicking my button and dragging it, and right click and copy.
- 01:58 Now head back over to GitHub, and click this new SSH key.
- 02:02 You probably don't have any listed, I've got a bunch.
- 02:05 Just go ahead and click paste to paste it all in there.
- 02:08 You can give it a title if you want, but you don't have to.
- 02:10 And then just click add SSH key.
- 02:13 It may or may not ask you for your password.
- 02:15 I haven't logged in a while, so it's asking me for my password.
- 02:17 And that's all there is to it.
- 02:19 So now, we need to head over to your repositories.
- 02:23 We need to create a new repository for this project.
- 02:27 So you can see I've got 51 different projects already on here.
- 02:31 If you've got a course of mine, you can look at the code here.
- 02:36 But let's click New, let's just name it.
- 02:38 Let's call this My Django resume, name anything you want.
- 02:41 And here you can toggle between public or private, right?
- 02:46 It used to be pay for private, but Microsoft recently bought GitHub and
- 02:50 they've done away with that.
- 02:51 And now everything is free, which is very cool.
- 02:55 And now just click Create Repository.
- 02:57 And we're almost done, we need to push our original code to our new GitHub repository
- 03:02 and we do that right here.
- 03:04 So we need to copy these two commands into our terminal.
- 03:08 So I'm going to highlight this and click Copy.
- 03:10 And let's head back over to our terminal and right click and just Paste,
- 03:15 and hit Enter.
- 03:16 First one's done.
- 03:17 Now finally, the next one, the last one, Copy,
- 03:22 head back over to our terminal, Paste it in.
- 03:27 And hopefully, are you sure you want to continue?
- 03:31 Yes, It is pushing our code up there.
- 03:36 And it's done.
- 03:38 So, now we can head back over here and I just click reload on this page and
- 03:44 you could see here's my django resume.
- 03:47 Or you can go to your repositories.
- 03:52 And here it is my django resume, click on it.
- 03:56 And here's our entire code for our entire project.
- 03:59 And notice, remember that commit message from the last video,
- 04:03 removed about page, you can see it right here.
- 04:06 All the commit messages are listed right here, which makes this super useful.
- 04:11 And, you could see here's the files.
- 04:14 We actually did things too, when we remove the about page, very cool.
- 04:19 So, our code is up there, in the future if we want to make changes to our code.
- 04:25 So let's go to our homepage and
- 04:27 let's change this to John Elder's Tech Resume, right?
- 04:30 So we save this file, this is a major change.
- 04:32 We've got to save this to git and push it to GitHub, right?
- 04:39 Normally, you wouldn't for something so tiny.
- 04:42 But let's pretend this is a big change and we want to save this to GitHub.
- 04:45 So let's walk through this one last time.
- 04:46 So I'm going to clear the screen.
- 04:48 So we need to git add period to add it to our local repository.
- 04:52 We need to git commit -am.
- 04:55 And let's say, changed homepage title, right?
- 05:02 Now to push our code up to GitHub in the future forever,
- 05:06 from now on, we just type in git push.
- 05:12 And that's it.
- 05:13 So now we can head back over here.
- 05:15 And if we go back here to our django resume and
- 05:18 click reload, We see changed homepage title, right here.
- 05:24 Where did it do that?
- 05:26 Well, we did it in templates.
- 05:29 So let's click there.
- 05:30 Changed homepage title on our home.html page.
- 05:33 Okay, so let's look at that.
- 05:35 And we can see sure enough, if we kind of scroll down here,
- 05:39 it now says, John Elder's Tech Resume right there.
- 05:43 So very, very cool, all right?
- 05:45 So that's GitHub, that's version control.
- 05:47 Super simple, and very useful.
- 05:50 So in the next video, we're going to look at Heroku and start to install some things
- 05:55 we need in order to push our code to Heroku, and that'll be in the next video.
Lesson notes are only available for subscribers.