1 00:00:00,560 --> 00:00:03,340 We've told you that Git can keep you from losing work and 2 00:00:03,340 --> 00:00:06,140 that it can help teams work together on projects. 3 00:00:06,140 --> 00:00:08,610 But how exactly does it do that? 4 00:00:08,610 --> 00:00:10,830 Git is a version control system. 5 00:00:10,830 --> 00:00:14,940 It helps you control the different versions of the files in your project. 6 00:00:14,940 --> 00:00:18,330 It keeps track of all the changes to your files over time. 7 00:00:18,330 --> 00:00:23,369 If you ask it to, it can reset any files contents to match a previous version. 8 00:00:23,369 --> 00:00:24,467 Or, more commonly, 9 00:00:24,467 --> 00:00:28,520 you can reset the version of all the project files at the same time. 10 00:00:28,520 --> 00:00:31,490 The collection of all the old versions of your projects files 11 00:00:31,490 --> 00:00:33,950 is known as a Git repository. 12 00:00:33,950 --> 00:00:37,050 It's basically a folder in which you can edit your files 13 00:00:37,050 --> 00:00:40,410 then run Git commands to store your changes. 14 00:00:40,410 --> 00:00:43,820 You can have multiple Git repositories on your computer, one for 15 00:00:43,820 --> 00:00:45,950 each project you're working on. 16 00:00:45,950 --> 00:00:48,720 So at this point you may be thinking Git is just like 17 00:00:48,720 --> 00:00:52,540 network backup software like Dropbox or Google Drive, right? 18 00:00:52,540 --> 00:00:53,350 After all, 19 00:00:53,350 --> 00:00:57,850 those programs store a new version of a file every time you save it too. 20 00:00:57,850 --> 00:01:00,948 But Git is way more powerful than just making backups. 21 00:01:00,948 --> 00:01:05,904 For one thing, it's intended to help developers work together on a project. 22 00:01:05,904 --> 00:01:11,130 With just a couple commands, you can clone an entire repository to another computer. 23 00:01:11,130 --> 00:01:15,240 This clone will include the full version history of all the files. 24 00:01:15,240 --> 00:01:17,420 Once they have the files on their own machine, 25 00:01:17,420 --> 00:01:19,534 other people can make their own changes. 26 00:01:19,534 --> 00:01:23,260 And Git includes commands that let you easily bring changes from 27 00:01:23,260 --> 00:01:26,980 other people's repositories back into your repository. 28 00:01:26,980 --> 00:01:30,530 Each time you complete a change to some or all of your project's files, 29 00:01:30,530 --> 00:01:33,600 you can take a snapshot of their current contents. 30 00:01:33,600 --> 00:01:37,230 This snapshot represents a point in your project's history that you might want to 31 00:01:37,230 --> 00:01:39,940 travel back to some time in the future. 32 00:01:39,940 --> 00:01:42,910 These snapshots are known as commits. 33 00:01:42,910 --> 00:01:46,180 Just as you might take a phone number and commit it to memory so 34 00:01:46,180 --> 00:01:50,210 you can remember it later, you can commit a version of your projects files to 35 00:01:50,210 --> 00:01:54,360 your Git repository, so you can get that version back later. 36 00:01:54,360 --> 00:01:57,570 But most version control programs have features like this. 37 00:01:57,570 --> 00:02:00,185 Why is Git in particular so popular? 38 00:02:00,185 --> 00:02:03,620 There is a variety of reasons for this, but here's an important one. 39 00:02:03,620 --> 00:02:08,910 Git is a distributed version control system as opposed to a centralized system. 40 00:02:08,910 --> 00:02:13,480 In a centralized system, the repository with all the old versions of files lives 41 00:02:13,480 --> 00:02:16,580 in only one place, a central server. 42 00:02:16,580 --> 00:02:19,160 If anything happens to that central repo and 43 00:02:19,160 --> 00:02:23,170 you don't have current backups, all the old versions will be lost. 44 00:02:23,170 --> 00:02:26,780 In a distributed system, you can copy a complete repository 45 00:02:26,780 --> 00:02:30,910 with the full project history to every developer's machine. 46 00:02:30,910 --> 00:02:33,940 Commands are available to synchronize repos with each other as new 47 00:02:33,940 --> 00:02:35,520 changes are made. 48 00:02:35,520 --> 00:02:37,650 If anything happens to one of those repos, 49 00:02:37,650 --> 00:02:40,650 the data in any other repo can be used to restore it. 50 00:02:41,790 --> 00:02:44,880 Let’s open up a workspace and try our first Git command. 51 00:02:44,880 --> 00:02:46,620 It’s not going to look like much, but 52 00:02:46,620 --> 00:02:50,320 Git’s plain looking command line interface hides some major power. 53 00:02:50,320 --> 00:02:52,710 You’ll see what we mean over the rest of the course. 54 00:02:52,710 --> 00:02:55,020 If you’re watching this video on the Treehouse site, 55 00:02:55,020 --> 00:02:58,450 there should be a Launch Workspace button on the page, so click that. 56 00:02:59,560 --> 00:03:02,950 You'll see a dialog where you can rename your workspace if you want. 57 00:03:02,950 --> 00:03:05,520 Click the Launch it button when you're ready. 58 00:03:05,520 --> 00:03:08,380 A new window will open with a Treehouse workspace. 59 00:03:08,380 --> 00:03:09,380 Give it a minute to load. 60 00:03:10,650 --> 00:03:13,740 You'll see the sidebar with the list of files in this workspace, and 61 00:03:13,740 --> 00:03:17,560 a text editor, but we're not going to use those much in this course. 62 00:03:17,560 --> 00:03:21,020 What we want is the console panel down here at the bottom. 63 00:03:21,020 --> 00:03:22,840 Let's resize that so we have more room. 64 00:03:25,692 --> 00:03:27,740 Next, we need to activate the console. 65 00:03:27,740 --> 00:03:29,910 Click anywhere within the console panel. 66 00:03:29,910 --> 00:03:33,770 You'll know it's been activated if a blinking cursor appears down there. 67 00:03:33,770 --> 00:03:37,500 This is a prompt for Bash, a command shell that runs on many Mac, 68 00:03:37,500 --> 00:03:41,320 Linux, and even some Windows computers when you open their terminals. 69 00:03:41,320 --> 00:03:43,780 This particular prompt shows the current username and 70 00:03:43,780 --> 00:03:46,820 then the name of the directory or folder that we're currently in. 71 00:03:46,820 --> 00:03:49,590 It's a directory named workspace, in this case. 72 00:03:49,590 --> 00:03:52,230 Bash prompts usually end in a dollar sign. 73 00:03:52,230 --> 00:03:55,990 When you read Git tutorials out on the web, you may see a dollar sign. 74 00:03:55,990 --> 00:03:59,140 That usually indicates that the text following it should be typed at 75 00:03:59,140 --> 00:04:00,470 a shell prompt. 76 00:04:00,470 --> 00:04:04,100 Note that when following along with a tutorial, you should not actually type 77 00:04:04,100 --> 00:04:07,640 the dollar sign unless it appears somewhere in the middle of the command. 78 00:04:07,640 --> 00:04:09,260 Now we need to run Git. 79 00:04:09,260 --> 00:04:12,570 Git is installed on a system, like it is here in this workspcae. 80 00:04:12,570 --> 00:04:17,380 It places an executable named git where it should be run from any shell prompt. 81 00:04:17,380 --> 00:04:19,270 This is the git command. 82 00:04:19,270 --> 00:04:22,230 All the commands we're going to show you during this course will use this 83 00:04:22,230 --> 00:04:23,010 executable. 84 00:04:23,010 --> 00:04:26,290 So they're all going to start with git followed by a space. 85 00:04:26,290 --> 00:04:29,400 Then we need to specify the sub-command or options we want. 86 00:04:29,400 --> 00:04:32,270 For this first command, we're not going to run any sub-commands. 87 00:04:32,270 --> 00:04:35,380 We're just going to git help on the git command itself. 88 00:04:35,380 --> 00:04:38,750 We do this with a command line option. 89 00:04:38,750 --> 00:04:42,930 Git options consist of either a single dash followed by a single letter, or 90 00:04:42,930 --> 00:04:45,470 a double dash followed by a word. 91 00:04:45,470 --> 00:04:48,430 In this case, we want the help option. 92 00:04:48,430 --> 00:04:51,620 Once you've typed all that, your command is complete, so press Enter or 93 00:04:51,620 --> 00:04:53,330 Return to run it. 94 00:04:53,330 --> 00:04:57,190 git --help will print out some help on using the git program. 95 00:04:57,190 --> 00:04:57,790 By the way, 96 00:04:57,790 --> 00:05:01,290 it's okay if the output you see doesn't exactly match what's shown here. 97 00:05:01,290 --> 00:05:04,300 It just means you're running a different version of Git than I am. 98 00:05:04,300 --> 00:05:07,050 All the commands we show in this course will work the same way 99 00:05:07,050 --> 00:05:09,240 no matter what version of Git you have. 100 00:05:09,240 --> 00:05:12,260 The only part of this output that's really useful to us right now 101 00:05:12,260 --> 00:05:14,170 is this list of subcommands. 102 00:05:14,170 --> 00:05:17,230 These are used to invoke most of Git's basic functionality. 103 00:05:17,230 --> 00:05:20,200 And we'll be trying out many of them during this course. 104 00:05:20,200 --> 00:05:24,810 The git clone and git init commands are used to set up new repositories. 105 00:05:24,810 --> 00:05:26,600 The git add, git status, and 106 00:05:26,600 --> 00:05:30,610 git commit commands are the most frequently used subcommands in all of Git. 107 00:05:30,610 --> 00:05:33,690 They're used when committing new versions of files. 108 00:05:33,690 --> 00:05:35,940 The git log command is also important. 109 00:05:35,940 --> 00:05:38,360 It lets you view a list of your old commands. 110 00:05:38,360 --> 00:05:41,000 The git move and git remove commands move and 111 00:05:41,000 --> 00:05:43,300 remove files that are being tracked by Git. 112 00:05:43,300 --> 00:05:46,080 We'll learn about those in stage two of this course. 113 00:05:46,080 --> 00:05:50,150 And the git push and git pull commands are used to synchronize commits with Git 114 00:05:50,150 --> 00:05:52,340 repositories on other computers. 115 00:05:52,340 --> 00:05:54,780 We'll learn about those in stage three. 116 00:05:54,780 --> 00:05:57,480 That's an overview of the most basic Git commands. 117 00:05:57,480 --> 00:06:00,350 Up next, we 'll show you how to create a Git repository.