Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
What Is Version Control?.docx59.2 KB What Is Version Control? - Solution.docx
59.4 KB
Quick reference
What Is Version Control?
Version control is incredibly important to computer programming, no matter what language or framework you use! It allows you to track changes to your code over time, and back it up in case of emergency.
When to use
Version control is something you'll use every day. Any time you make a significant change to your code, you'll need to version control save it.
Instructions
To set up Git the first time, enter these commands in the terminal:
- git config --global user.name "Your Name"
- git config --global user.email "you@youraddress.com"
- git config --global push.default matching
- git config --global alias.co checkout
- git init
Be sure to use the same email address that you plan to use later on at github.com
To Save your code and commit your changes, use these two commands in the terminal
- git add .
- git commit -am "Commit Message Here"
Version control is a great way to back up code, but it also helps several developers to work on code in groups and merge their code together in the future.
Hints & tips
- Git is the type of version control we'll use
- Git is run locally on your cloud development environment
- After we save our file with Git, we'll push it to github.com for safe keeping
- 00:05 In this video, we're going to talk about something that pretty important to coding
- 00:08 in general regardless of which programming language you use or
- 00:11 what your trying to build.
- 00:13 Talking about version control.
- 00:15 Now version control is a way to keep track of the changes to your code overtime.
- 00:19 It's also a way to sort of backup your code in case of emergencies.
- 00:22 Why is it important?
- 00:24 Well, I can't tell you how many times I've had perfectly fine code and
- 00:27 then I decided to add an additional feature or add something else.
- 00:31 So I start hacking around on the code and a few hours later, the thing I'm trying to
- 00:35 build is a mess, it doesn't work, the whole thing's been destroyed,
- 00:38 I don't know what happened, I don't know how to fix it.
- 00:41 And it is just an absolute mess, well with version control you can just issue one
- 00:46 command in roll your code back a few hours to when it did work and everything's fine.
- 00:52 So, it's just so very important that you always use version control.
- 00:56 It's also good for teams that are collaborating, it allows you to keep track
- 01:00 of who did what and when and it also allows you to merge your code.
- 01:03 So if you're working on code and your partners working on code and
- 01:06 then you wanna merge those two pieces of code together,
- 01:09 version control will let you do that, just very important.
- 01:12 So there are several popular versions of version control out there some of
- 01:16 the names that are Subversion, Git and Mercurial, those are some of the names
- 01:20 you'll hear. In my opinion Git is the the most popular one.
- 01:23 And so that's what we're gonna be using through out this course,
- 01:26 GIT has been around forever and it's just really easy to use.
- 01:28 So Git is a program, it's G-I-T, Git and
- 01:31 it's sit on your local development environment or your local computer.
- 01:37 In our case, it sits in our C9 development environment.
- 01:40 Like l said this is a Linux server and
- 01:43 most of the time Linux has Git installed on it and this one already has it so,
- 01:46 we don't have to install anything, we just need to turn it on.
- 01:49 The one more thing before we actually start using it,
- 01:52 Git is local, so it resides right here in our local development environment, but
- 01:56 keeping your code just locally is not really a good idea something would happen,
- 02:01 if this server crashed everything disappeared or
- 02:03 code would be gone, that's bad.
- 02:05 So it's always a good idea your stuff and push your code to third party,
- 02:09 in our case we're gonna be using GitHub.
- 02:12 It's also service called BitBucket that's very similar and
- 02:15 I'll talk about, in the next couple of videos, why you'd choose one or the other.
- 02:18 But it's important to designate between the two, there's Git and
- 02:22 there is a GitHub and the two very different things.
- 02:25 Git did all the stuffs locally and then we push the code up to GitHub it's sort of
- 02:29 a repository as a place to backup your code basically.
- 02:33 We will get in all that in the next video and this video, very quickly, we need to setup
- 02:38 Git and turn it on and I'll teach you the basic commands in order to use it.
- 02:43 They're very simple, we just need to type in three or four different commands and
- 02:46 they're sort of long commands, but it's not too bad.
- 02:49 So just follow along here, you might wanna write this down,
- 02:51 'cause you'll always do this every time you develop something online.
- 02:54 These are the same commands you''' use every time, so
- 02:56 it's good to memorize them or at least write them down.
- 02:59 To get started we type in git config --global user.name,
- 03:06 and then type in your name, in quotes, and then hit Enter.
- 03:13 Now we type in git config --global user.email and
- 03:18 type in your email address and it's important to
- 03:23 use this same email address that you plan on using in
- 03:28 the future at GitHub, so that you need to connect.
- 03:33 So the next command is git config --global
- 03:42 push.default matching
- 03:47 And then git config --global alias.co checkout and
- 03:55 that's it, now I need to turn it on and
- 04:00 to be there we type in git init.
- 04:05 And what it's done is,
- 04:06 it's created a repository this period before that means it's a hidden directory.
- 04:11 It's located in the workspace directory which is this pinteresting directory but
- 04:15 doesn't show up here, 'cause like I said it's hidden.
- 04:18 And now we have Git up and running now to use Git type in clear to clear the screen.
- 04:24 Every time we wanna save our code,
- 04:26 we need to issue the couple of commands to do that.
- 04:28 So, let's just do for the first time,
- 04:31 type in git add, then a space and then a period, and
- 04:34 the period means we're gonna save all the files and all the directories on our system.
- 04:39 Hit Enter, now we type git commit -am and we wanna give this a message,
- 04:44 every time you save your code, you wanna give it a little message,
- 04:48 it helps to keep track of changes over time.
- 04:51 You can look at those messages, and sort of get an idea where you are at.
- 04:54 So, for the first one, we are gonna do "Initial Commit" and
- 04:59 what we're doing is committing our code to your repository.
- 05:03 And you can see, re-size this. It's saved all of the files and
- 05:08 everytime you do this, it'll save all the files that you've
- 05:13 change since the last time you made a commit, so go ahead and clear that, and now we're done.
- 05:20 In the next video I'll show you how to push your code up to GitHub.
- 05:23 But for right now, we are ready to go.
- 05:26 We've got version control up and running, we've made our initial commit.
- 05:29 We've saved all our code for the first time and that's all for this video.
Lesson notes are only available for subscribers.