Locked lesson.
About this lesson
Setting up Version Control in our cloud development environment.
Exercise files
Download this lesson’s related exercise files.
Version Control With Git.docx58.7 KB Version Control With Git - Solution.docx
59.2 KB
Quick reference
Version Control with Git
Version control is an important tool for any programmer to use.
When to use
Version control should be used whenever you write code.
Instructions
Version control allows you to keep track of changes to your code over time. It allows you to keep backups in case something goes wrong, and allows more than one programmer to collaborate on a project.
To set up git in your 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
To save your code:
git add .
git commit -am "Commit Message"
Hints & tips
- There are many types of version control systems.
- We'll be using git as our version control.
- 00:04 In this video I want to talk about version control.
- 00:07 And version control is not a PHP thing, it's a coding thing.
- 00:10 Anytime you're writing code you want to save it.
- 00:13 Now obviously,
- 00:14 we're going to save it by hitting Ctrl+S in our Sublime text editor here.
- 00:17 But that's not what I'm talking about, version control is slightly different.
- 00:20 Version control keeps track of who made changes,
- 00:23 when they made changes, it keeps track of old versions as you go.
- 00:28 So if you do something to kind of screw up your code,
- 00:30 you can roll it back to an older version.
- 00:32 It's great for teams, so if you're working on a team with a lot of other people,
- 00:36 it keeps track of who makes the changes.
- 00:38 If Bob over there makes a mistake, it records that Bob did that,
- 00:42 then you can roll that back later on.
- 00:44 So, it's just super important in programming in general, and
- 00:47 it's just a good idea to set up version control anytime you're coding.
- 00:51 You need a couple of tools to do that, and you need a terminal mainly with Git.
- 00:55 And if you're on a Mac or Linux, it comes with a terminal, you can just go to your
- 00:59 search function and search terminal and use that, that's perfectly fine.
- 01:02 But Windows doesn't have a great terminal.
- 01:04 So we need to download and install one.
- 01:06 And the one that I like is called Git Bash.
- 01:10 So you just head over to Google and type in Git Bash.
- 01:12 And this is the Web site, git-scm.com/downloads.
- 01:17 And if this version changes by the time you watch this video, no big deal,
- 01:20 just go ahead and download the latest version.
- 01:22 So click here.
- 01:24 It should download.
- 01:25 Now save this anywhere.
- 01:26 I'm just going to save it on my desktop.
- 01:28 And this is a notoriously slow website, usually takes a while for
- 01:31 this to download.
- 01:32 Okay, so once that's finished downloading,
- 01:35 you can click this to run the installation program.
- 01:38 And I'll walk you through this,
- 01:40 it's slightly more complicated than you might expect.
- 01:43 It's not actually hard, but there's a whole lot of stuff here.
- 01:46 All right, so go ahead and click Next here, we just want the defaults for
- 01:49 all of these, and here it asked what text editor we're going to be using.
- 01:52 Sublime is the first one it lists and this is kind of weird because this terminal
- 01:56 won't interact with Sublime in any way.
- 01:59 So if you don't use Sublime, it doesn't really matter,
- 02:02 just leave it as Sublime and go ahead and click Next.
- 02:05 Click Next, we just want the default here, we want the default here, and
- 02:08 we want the default here.
- 02:10 We want the default here as well.
- 02:11 Basically, we're going to take the default for all of these things.
- 02:14 Click Next.
- 02:15 And finally, click Install.
- 02:17 Now, I'm not going to do this because I've already installed it on my compter.
- 02:20 But you'll go ahead and click Install and
- 02:22 it'll just finish the installation process.
- 02:24 So I'm going to click Cancel.
- 02:26 Now just head over to your Windows start menu and type in G-I-T and
- 02:31 then it should pop up.
- 02:33 So here it is, now your screen will look a little different,
- 02:35 my computer is called flatplanet.
- 02:37 I don't think the world is flat, I just find it kind of funny that some people do,
- 02:40 so I named my computer that.
- 02:41 Whatever your logged in username is or computer name is,
- 02:44 you'll see this right here.
- 02:45 The first thing we need to do is navigate to the directory where we're saving all
- 02:49 of our files.
- 02:50 So we use the cd command, it stands for change directory.
- 02:53 And we want to move to cd xampp.
- 02:56 And remember we're in the htdocs directory, inside of that.
- 03:00 And then inside of that, we want php-course.
- 03:04 So you can see if we type in pwd, it shows us that in fact, yep,
- 03:08 we're in that directory.
- 03:09 Now, we can type ls to list the stuff in this directory, and
- 03:12 the only thing in there is that index file we just created in the last video.
- 03:16 So okay, so far so good.
- 03:18 Go ahead and clear the screen.
- 03:20 Now, in order to set up git for the first time, we need to issue some commands.
- 03:24 We just need to type in four or
- 03:25 five little commands here to get this initialized.
- 03:28 So type in git config --global user.name and then your name.
- 03:34 Remember I told you git keeps track of who makes what changes.
- 03:39 So then git config --global user.email and
- 03:44 type in your email address.
- 03:47 And in the next video, we're going to push our code up to GitHub,
- 03:51 which is a third party website.
- 03:53 So you use the same email address you plan on using to sign up for
- 03:56 github.com, which is free and we'll talk about later.
- 03:58 All right, next we want git config
- 04:04 --global push.default space matching.
- 04:11 All right, two more, git config --global,
- 04:17 and then alias.co checkout.
- 04:20 And then finally get init, and this will initialize git.
- 04:25 And you see once we did that, now it says master.
- 04:27 So when you save your code to git, you're saving it to the master branch, right?
- 04:32 And if you want to make, think of like a tree,
- 04:35 different limbs off of the master branch, you can,
- 04:37 we're not going to get into that in this course, it's not really a course on git.
- 04:41 We're just going to be using basic functionality.
- 04:43 So now, we can clear the screen.
- 04:45 Now from now on, anytime we want to save a version of our code,
- 04:49 we just type in get add period.
- 04:52 And the period stands for everything, it's going to add everything in this directory.
- 04:56 In our case, we only have one file.
- 04:58 Then we type in, git commit -am and then give this a little message.
- 05:04 I'm going to call this initial commit.
- 05:07 And every time you type a message, sort of describe what you just did with your code.
- 05:12 So if you made a major change to your code, where you added a new about page,
- 05:17 you would type in added about page as your little message.
- 05:21 And you'll see why these messages are important later on.
- 05:24 And that's it, we've now committed our code to the master branch or
- 05:28 get repository and we're good to go.
- 05:30 Now in the next video, I'm going to talk about pushing all of these stuff to GitHub
- 05:35 which is a third party website that sort of keeps track all the stuff for you, and
- 05:39 that'll be in the next video.
Lesson notes are only available for subscribers.