Locked lesson.
About this lesson
Setting up "Git" for version control in our development environment.
Exercise files
Download this lesson’s related exercise files.
Version Control with Git.docx59.9 KB Version Control with Git - Solution.docx
60.4 KB
Quick reference
Version Control with Git
Version control is very 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 git bash 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
Sign up for an account on github.com.
To Save your code and commit your changes, use these two commands in the git bash 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.
- After we save our file with git, we'll push it to github.com for safe keeping.
- 00:04 We have one more basic intermediate thing to talk about, and
- 00:08 that is discuss version control.
- 00:10 And version control is a way to save your code in steps as you go forward.
- 00:15 That's really important, because if you mess something up, you need to be able to
- 00:19 roll your code back to a time when it wasn't messed up in order to fix it.
- 00:23 Also, if you're working with other developers and you're collaborating and
- 00:26 you're all writing code, you need some sort of system that keeps track of who
- 00:30 wrote what code and when and then merges all the code together correctly.
- 00:34 In the web development world,
- 00:35 the most popular type of version control is called Git.
- 00:39 And Git is already installed in our development environment here.
- 00:42 We just need to turn it on and start using it.
- 00:44 Now before we do that, there's two steps to Git.
- 00:47 There's Git and then theirs GitHub.
- 00:49 And GitHub is a website.
- 00:51 If you go to GitHub.com and it's a place where you can push your code and
- 00:55 save it in the cloud.
- 00:56 And that's important because something could happen to this Cloud9 website.
- 01:00 It could crash.
- 01:01 It could get hit by hackers.
- 01:03 You could accidentally delete your code here and it would be gone forever.
- 01:06 So it's always a good idea to back up your code somewhere else.
- 01:09 And GitHub is the place where were going to do this.
- 01:11 It's where a ton of people, I mean, most developers use GitHub.
- 01:15 So the first step is to set up Git.
- 01:18 Like I said, it's already installed on here, but
- 01:19 we need to sort of initialize it and turn it on and set some configuration stuff.
- 01:24 But you'll need to download a little terminal tool
- 01:27 to do these things on Windows.
- 01:29 Now if you're on Mac or Linux, you already have a terminal.
- 01:31 Just go to the little search function on your computer and search for
- 01:34 terminal and use that.
- 01:37 But if you're on Windows, head over to Google and type in git bash, and
- 01:42 you see this website, it is git-scm.com/downloads.
- 01:46 And this is the git bash terminal.
- 01:48 It's a free little terminal that we can use, and it's really cool and easy.
- 01:51 So we're on version 2.22.0.
- 01:54 If that changes by the time you watch this video, no big deal,
- 01:56 just download the latest version.
- 01:58 So go ahead and click Download, and we can save this anywhere.
- 02:02 I'm just going to save it to our Desktop.
- 02:04 It takes a little bit to download, it's only 44 megabytes but
- 02:07 this website is really slow.
- 02:09 So once it finishes downloading, go ahead and click it to install it.
- 02:12 And just click the Next button.
- 02:14 And there's a whole bunch of stuff here, we're just going to click Next for
- 02:17 everything.
- 02:18 We don't want to change any of these settings, just take the defaults for
- 02:21 all of them.
- 02:25 Next, Next, Next, Next.
- 02:28 And then finally, click this Install button.
- 02:29 I'm not going to do it because I've already installed it on my computer.
- 02:31 But you go ahead and click it to finish the installation.
- 02:34 Once it's finished, head over to your Windows Start Menu and
- 02:39 type in git bash, G-I-T B-A-S-H.
- 02:42 And when you do, this will appear.
- 02:44 So the first thing we need to do is navigate into
- 02:47 the folder that is holding all of our HTML file.
- 02:50 Type in cd, stands for change directory, and then c and then basic-html.
- 02:57 That's the folder we've been using.
- 02:58 And so we can see we're in this directory right there.
- 03:01 Now I'm going to go ahead and clear the screen.
- 03:03 Now, in order to initialize Git, in order to set it up for the first time,
- 03:07 we have to type in four or five commands.
- 03:10 So the commands are git config --global,
- 03:16 User.name and then quotation marks, and then type in your name.
- 03:21 Git needs to keep track of who does what to the code, so
- 03:24 it needs your name to do that.
- 03:25 The next one is git config --global user.email and
- 03:31 type in your email address.
- 03:37 Now, in the next video, we're going to push all of our code up to GitHub.
- 03:40 So you want to use the same email address that you plan to use at github.com.
- 03:46 Next we type in git config --global
- 03:52 push.default matching.
- 03:58 Then git config --global Alias.co check out,
- 04:05 and then finally get a init.
- 04:09 This turns it on.
- 04:10 Now, I don't remember what any of these commands are.
- 04:13 I've been using the same commands for decades.
- 04:16 This is just the thing you have to do the first time in order to set up Git,
- 04:20 like I said just one time.
- 04:22 And you can see now it says master right here.
- 04:25 And master stands for the master branch.
- 04:28 With Git version control,
- 04:29 you're saving copies of your code to the master branch, right?
- 04:34 So think of a tree that has branches.
- 04:37 If you want to make changes in the future,
- 04:38 you can branch off from your master branch and do other things.
- 04:41 We're not going to get into all that in this video, but that's what that means.
- 04:45 So we can go ahead and and type clear to close the screen.
- 04:48 And like I said, if it says master here, you you've done everything correctly.
- 04:51 So now we need to save our code to Git.
- 04:54 And anytime we want to save our code, we just type in git add period.
- 04:59 And the period stands for everything.
- 05:01 It's going to add everything in this basic HTML directory to our Git repository.
- 05:08 And then we type in git commit -am.
- 05:11 We want to commit the changes to our code.
- 05:13 And now we want to write a little message.
- 05:15 And I'm just going to type in initial commit.
- 05:20 This is our first commit, the initial commit.
- 05:23 Anytime you make major changes to your code and you want to save it,
- 05:26 write a little descriptive message right there.
- 05:29 So if you've created an about page,
- 05:31 I would type in 'created an about page' as this message right here.
- 05:36 So again, just sort of be descriptive.
- 05:40 And boom, we're done, so that's Git.
- 05:42 In the next video,
- 05:43 we'll look at github.com to push all of our code up to github.com for safekeeping.
- 05:49 And we'll talk about why that's important.
- 05:50 And that'll be in the next video.
Lesson notes are only available for subscribers.