Locked lesson.
About this lesson
In this lesson, we will learn how to set up version control with Git.
Exercise files
Download this lesson’s related exercise files.
Git Version Control.docx57.5 KB Git Version Control - Solution.docx
58.4 KB
Quick reference
Git Version Control
Version control allows you to save versions of your code over time.
When to use
You should set up version control at the beginning of every new project you create.
Instructions
To set up Git version control, type these five commands into the terminal (one at a time):
$ 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
Hints & tips
- Version control allows you to save your code over time.
- Set it up at the beginning of every project you create.
- 00:04 Okay, in this video we want to set up version control with git, and
- 00:08 version control is something that all coders use, right?
- 00:11 It allows us to save versions of our code as we're moving along.
- 00:15 Now, normally we would have set up version control right at the beginning,
- 00:18 when we started building out our project.
- 00:20 But our project is very simple and
- 00:22 there wasn't any real reason to save it as we went along.
- 00:25 So I just waited till now to show you guys how to do it.
- 00:28 And git is super useful if you're on a team.
- 00:31 So if you've got a bunch of people working on some code,
- 00:34 git will keep track of who made what changes to the code.
- 00:37 So you kind of check out code, you modify it, you save it to git.
- 00:41 It keeps track of, you changed this thing,
- 00:44 Bob over there changed this other thing, Mary over there changed something else,
- 00:49 and it sort of merges all of those changes together.
- 00:52 And also it just keeps track of your code over time.
- 00:56 So if you're coding along, and all of a sudden you blow up your app,
- 00:59 you do something horrible, and you can't figure out what you did.
- 01:03 That happens a lot.
- 01:04 You could just roll back to a previous version of your git that you had saved,
- 01:08 and go on from there.
- 01:09 So it's just super useful.
- 01:11 All coders use it, and that's what we're going to set up in this video.
- 01:15 So our git bash terminal already comes with git, we just need to turn it on and
- 01:19 start using it.
- 01:20 So from our terminal, from our Django website directory,
- 01:23 we need to enter four or five commands.
- 01:26 And the first one is git config --global
- 01:31 user.name, and then your name.
- 01:35 So john Elder.
- 01:37 And I'll put these in the resource file, so you can copy and
- 01:40 paste them if you want.
- 01:41 But they're pretty simple.
- 01:42 So the next one is git config.
- 01:47 They're all git config, basically, --global user.email and
- 01:54 then your email, john@codemy.com.
- 01:58 All right, the next one is git config
- 02:04 --global push.default matching.
- 02:10 The next one is git config, you guessed it,
- 02:15 --global alias.co checkout, and then finally git init.
- 02:23 This will initialize git.
- 02:24 And when we do, we see this master thing pop up next to our terminal.
- 02:30 Now, you may be asking what all of these commands do.
- 02:33 I'm going to be absolutely honest.
- 02:35 I have no idea.
- 02:36 I learned this stuff over a decade ago.
- 02:38 I knew what it was at the time.
- 02:40 I don't remember exactly what these things are doing and you really don't have to.
- 02:45 That's the point.
- 02:46 You just have to do this once per project every time you set up git.
- 02:50 Now from now on, we don't have to do this stuff.
- 02:52 So we don't really care what it does.
- 02:54 All right, let's go ahead and clear the screen.
- 02:55 So now we want to save our code to git.
- 03:00 So to do that it's a two step process.
- 03:02 We're type in git add period.
- 03:04 And what this is doing is it's adding all of the files in our project, right?
- 03:09 git add period, the period stands for everything.
- 03:13 Now we've added those files, now we need to commit them, and
- 03:17 committing is sort of like saving them.
- 03:19 We're saving them to our repository.
- 03:23 So to do that we type in git commit -am and then give this a little message.
- 03:30 I'm going to call this initial commit, right?
- 03:34 And boom, everything has been added.
- 03:36 Now that's all there is to it.
- 03:38 We've now saved our files to git.
- 03:40 Now in the future, in the next video, we'll set up GitHub,
- 03:43 which is a website where you can push your git code for safekeeping.
- 03:47 And we'll look at that in the next video.
- 03:49 But as far as just locally, this is all you have to do.
- 03:52 Now, every time you make a major change to your code,
- 03:55 you're going to want to save your code again.
- 03:57 So let's go through that real quick.
- 03:59 We've got this about page.
- 04:00 We don't really need this.
- 04:01 So let's get rid of it.
- 04:03 So let's save it from our views.py.
- 04:05 We've got the URL, we can take that out.
- 04:08 Let's just take that out.
- 04:10 Save this.
- 04:12 And we've got a template file floating around somewhere of about.html,
- 04:17 don't need that.
- 04:18 So let's get rid of that.
- 04:20 So we've deleted some stuff.
- 04:22 We deleted some files, we've modified some files, let's head back over to
- 04:28 our terminal and and save these changes to git, so git add period.
- 04:34 Git commit -am and let's say removed about page.
- 04:38 And that's what this little message is.
- 04:40 You just want to be descriptive about what you just did, and why you're saving it,
- 04:45 right.
- 04:45 And you'll see in the next video why this is important,
- 04:48 but it's just a little descriptive thing that helps you keep track
- 04:52 over time of different commits that you have.
- 04:55 And we'll see why this is important, like I said in the next video, so
- 04:58 go ahead and do that.
- 04:59 And you'll notice only five files were changed this time, whereas last time there
- 05:03 was a whole long list of things that filled up the whole screen,
- 05:07 because we only changed five files.
- 05:09 Very cool, and that's all there is to it.
- 05:11 So that's git, that's version control, in the next video, we'll look at GitHub.
Lesson notes are only available for subscribers.