[MUSIC] In this video I'm going to tell you about how to use git to back up your code. The basic concept is, that as you're working on your code, every so often you take a snapshot of the code and you upload it to a repository somewhere. And that means, if at some point you want to roll back to an old version, you can do that. And also, if you just want to sort of download the code easily onto another machine, you can also do that. And it keeps a record of all the sort of changes you've made to your code. So the sort of best way to use, or the simplest way is to use a website called GitHub. Now, GitHub provides the git service underneath it. So, what is git, anyway? Well, git's basically a tool which allows you to sort of maintain a set of files and to sort of upload those files to some sort of repository. And GitHub is effectively a system which provides that repository, so that with your git tool, you can push it onto GitHub. Now GitHub is also the place where loads of open source projects are being developed. And so if you look at the github.com web page, which we're going to do now, you see you can start searching. So let's say we search for meteor in the search box up there. You can see the first thing that comes up is the meteor code, so that tells you what? Great, meteor is an open source project. And you can go into the repository and what you have here is all the code that represents that particular part of the meteor framework. And you can browse around and look at all the code and see how it all works, and that's one of the beautiful things about open source projects is great for learning about how other people have done things. It also provides easy access to different components and so on. And most of the packages which you'll see in Meteor are open-source and probably are on GitHub somewhere. So what we're going to do is create our own repository on GitHub and use it to store our project files while we're working on our project. So how do we do that? Well, the first step is to register. So I click on sign in or sign up, up there. And you'll be presented with a form that you need to fill in. Where you have to sort of select a user name and an email address and the password. It's really straight forward. And you tap that in and then it will probably email you to confirm it and everything else. So the usual type of, sort of registration form. And we do all that. And it's free. And then once you've sorted that out you can then login. So you hit the sign in button, and here I am at the sign in form. And I've already got an account, so I'm going to log in to that. And so when you first login if you've got an active account and you're already sort of looking at different people's code and so on you'll get a kind of dashboard, which tells you what's been happening in all those different repositories. That's what we can see on my screen. But you'll probably start with something a lot sort of simpler than I have here. So what do we do next? Well, we can then start, we can jump to our own sort of profile page by clicking on this top right up here and going to profile. You can see here, we see the sought of the stuff I'm working on, the stuff I've created. And you can see I've got, I've set up my avatar there, and set up some details about where I live and so on. So what we want to do is create a new repository. And that's pretty easy. You just hit the plus button up there and do new repository. And you're then presented with the form which allows you to define the sort of characteristics of your new repository. So obviously you have to give it a name. I'm going to call it capstonetest. Okay. Then we have to give it a description, optionally. And you can only, if you've got a free account on GitHub, everything has to be public. But if you pay you can have private repositories. Then you can initialize these repositories with a readme. Normally you would create a readme file inside the repository, it is like the first file. And that sort of says what the repository is for. Okay, so I'm going to tell it to initialize it with one of those. I hit the big green button, create repository, and that's it. I now have my own source code repository on GitHub. So the next question is, okay well that's great, but how do I change the code, right? How do I add code to my repository. So, first of all, what we do is we go down tot he right hand side here. You see there's a thing called HTTPS clone URL. This is probably the simplest way to access your repository and add files to it. And we do it all through the command line. So, first of all, I'm going to copy that. Okay and copy that address, which if you look at it, well we will look at it in a minute. There's the address and I go into my console there and, let's just zoom in a bit. Let's say I am going to create repository in my home folder, which is where I am now and I just type git clone and then the name of the repository. And so you might not have git installed on your system yet. So if you want to do that, you have to then search for an installer for git. So git installer. And we'll provide links to where you can get this. And there should be different installers for the various platforms. So you can see there, we've got Mac OS, Windows, Linux, and even Solaris. Don't know how many of you are using Solaris, but anyway. There we go. So we can download the git system there. I've already done it, so I can then start running the command. So I do git clone, and you see that address has got my username and also the name of the repository I just created. When you do that it just goes away and downloads the repository. So if I do an LS I see I have got loads of folders in there, but if I go to my capstonetest folder. So you see I'm not in my capstonetest. You can see there's a read me file in there which is the original readme file. Let's as an example,edit that readme file. So I'm going to open readme, not sure what that's going to open in. We'll soon see. So it's opening in Xcode, so there's Xcode. But it's just a text file so you can open it in any text editor you're using to edit your code or whatever. You can see it hasn't got much in there. This is in mark down format, now we're not going to teach you about mark down. But it's basically a simple way of sort of like, defining a document with headings and so on. So that hash there means it's a heading. So this is a repo for my capstone project. Okay? So I've just edited the file, and then I save it. Like that, close. And then you see the size of the file's gone up from 15 bytes to 56 bytes, so that's my new code. Now, how do I then sort of save that up to GitHub? Well, so first of all, when you upload to GitHub, you have to choose which files you want to upload. So we do git, add readme, and we can type git status. Okay and it tells us what's going on and it says here, modify readme.md. Great, so it's detected I've made change to that readme file. And then I go git commit. Okay? And -a is quite useful. That will commit any changes that have been made to any of the tracked files. So not every file is tracked by default. Okay, so we're going to add a new file later and see what goes on there. But for the moment, It's tracking this readme file and changes to that. So -a means upload anything that's been changed that's being tracked, -m is how you specify a message. First commit, and exclamation mark. And you can just type a short message in there to explain why you're committing. Why are you uploading this copy of the code? Well it's a first commit. Oh, it doesn't like me having exclamation marks. Okay, git commit -o message first, commit, enter. Okay, that's good, and that's sort of prepared so a batch of changes to be uploaded. And the final step is to upload it. So I do git push. Okay, and then I have to login to GitHub. So my username, okay, and that's it. It's now uploading my changes, and if you want to make sure, you can then go into, the GitHub page, which we were looking at before. So that's the page from my repository, and because I changed the readme file, that should've changed then there. So you can see there's a few bits of information there. So, it's actually saying, first commit there. So it's sort of logging the files which are changed in my commitment signal on that message. That's the one I've changed. It's telling me I've changed it 36 seconds ago. And this is the updated file. So, that's the nice thing. If you go to readme.md file, it will automatically display it. Sort of an information page on your repository. Kind of a home page if you like. Great. So that's basically changing a file and then sort of saving it out. So that's just made an edit to the code. It's a sort of simple way of doing that. Now what if I want to add a new file? I'm going to do that next. So I'm going to create a new file in the folder. There's my folder there. And if I go into. So I'm going to create a new file, so if I touch, I'm going to call it test.js. And then open it. Okay and let's say I just make a really simply JS file, whatever. Right, as my simple as possible JS file. Save that. And then if I type git status, you can see it says untracked files there. So you see that, it's kind of highlighted the file in red and said that's an untracked file. So it's detected, I put a new file into the repository but I haven't officially told it to track it. So it would just ignore it if I do a commit. So first I need to add it. So I add the file to the repository with test.js. Git add test.js, that means it's now tracking it. So if I type git status again, you see it's now gone green, and it's saying that's a new file. And then, same thing, so I can do git commit minus message, sorry, minus everything that's being tracked, and message second commit. And then git push to push it up to GitHub. And I have to log in again. Okay, so let's go back over to here. Right, so you can see my test.js file has now appeared on the GitHub page. So there you go. So that's the basics of using GitHub to do version tracking on your file. There's loads of other things that git can do, but I just wanted to show you the absolute basic set functionality you need to create a repository, add and modify files, and push it up to the central server so that you can keep a backup. And of course, you can keep multiple copies of your source code on different machines and commit from different machines, and so on, if you want to get more elaborate. But this is the basics of how to use it. [MUSIC]