1 00:00:00,000 --> 00:00:04,704 [MUSIC] 2 00:00:04,704 --> 00:00:07,964 So far you've been working in Git all by yourself. 3 00:00:07,964 --> 00:00:12,820 But projects small enough to be maintained by a single developer are pretty rare. 4 00:00:12,820 --> 00:00:16,930 At some point, you're going to need a way to share your code with other developers 5 00:00:16,930 --> 00:00:20,520 and to merge all your work together into a product you can ship. 6 00:00:20,520 --> 00:00:21,550 Don't worry. 7 00:00:21,550 --> 00:00:24,710 Sharing and merging file changes are central features of Git. 8 00:00:25,750 --> 00:00:26,490 With Git, 9 00:00:26,490 --> 00:00:31,630 every developer has their own repository on their machine, called their local repo. 10 00:00:31,630 --> 00:00:36,970 Repos belonging to other developers on the project are referred to as remote repos. 11 00:00:36,970 --> 00:00:42,180 Each repo is a full copy of the original repo, including all the version history. 12 00:00:42,180 --> 00:00:46,420 Developers can make commits to their own repo independently of the others. 13 00:00:46,420 --> 00:00:50,710 Before beginning work on the new feature, you should use the network to pull commits 14 00:00:50,710 --> 00:00:54,940 other developers have made from a remote repo into your local repo. 15 00:00:54,940 --> 00:00:58,960 So that you have the latest version of the code then you can make your changes, 16 00:00:58,960 --> 00:01:01,100 and commit them to your local repo. 17 00:01:01,100 --> 00:01:04,730 Other developers will be able to pull the commits you've made over the network to 18 00:01:04,730 --> 00:01:07,060 their clones, so they can access them. 19 00:01:07,060 --> 00:01:11,040 Any git repository is capable of pulling from any other repo. 20 00:01:11,040 --> 00:01:14,360 Sometimes collaborators pull from each other's repos directly, 21 00:01:14,360 --> 00:01:15,810 as we've shown here. 22 00:01:15,810 --> 00:01:19,700 But it's more common to declare one repo the central repo. 23 00:01:19,700 --> 00:01:24,100 Developers clone this central repo to their local machines over the network, 24 00:01:24,100 --> 00:01:28,810 then each developer begins working on their own separate set of changes. 25 00:01:28,810 --> 00:01:31,820 A developer adds their changes to the central repo 26 00:01:31,820 --> 00:01:34,740 by pushing commits to it over the network. 27 00:01:34,740 --> 00:01:39,250 Other developers receive these commits by pulling them down from the central repo, 28 00:01:39,250 --> 00:01:42,580 and they can push up their own changes in return. 29 00:01:42,580 --> 00:01:47,430 This is the system that GitHub, Bitbucket, and other Git hosting services support. 30 00:01:47,430 --> 00:01:50,900 But how do you create all those repositories in the first place? 31 00:01:50,900 --> 00:01:54,570 The easiest way to get a new repo based off another is to clone it, 32 00:01:54,570 --> 00:01:56,100 to make a copy of it. 33 00:01:56,100 --> 00:01:59,550 This copy will have all the same files in the working directory, 34 00:01:59,550 --> 00:02:02,220 plus a full copy of the project's history. 35 00:02:02,220 --> 00:02:05,500 Normally you clone from one computer to another over the Internet or 36 00:02:05,500 --> 00:02:06,750 some other network. 37 00:02:06,750 --> 00:02:11,040 But we can also clone from one directory to another on the same computer and 38 00:02:11,040 --> 00:02:12,770 everything will work the same. 39 00:02:12,770 --> 00:02:15,705 We're going to do that while we get used to the commands. 40 00:02:15,705 --> 00:02:19,575 We need to be in the workspace directory, which contains our medals repo. 41 00:02:19,575 --> 00:02:22,865 If you just restarted your workspace, you'll already be there. 42 00:02:22,865 --> 00:02:25,395 But if we're currently in the medals repo directory, 43 00:02:25,395 --> 00:02:27,465 you'll need to change directories. 44 00:02:27,465 --> 00:02:30,855 We can get there by changing to the parent directory, that is, 45 00:02:30,855 --> 00:02:33,570 the directory that contains this one. 46 00:02:33,570 --> 00:02:37,190 Linux, Mac, and Windows shells all use two dots, 47 00:02:37,190 --> 00:02:41,200 two period characters to represent the parent directory. 48 00:02:41,200 --> 00:02:45,450 So now we're in the parent directory, the directory named workspace. 49 00:02:45,450 --> 00:02:48,100 Now, let's clone the medals repository. 50 00:02:48,100 --> 00:02:50,130 We do this with the git clone command. 51 00:02:51,780 --> 00:02:55,660 The first argument to git clone should be the location of the repository you 52 00:02:55,660 --> 00:02:56,830 want to clone. 53 00:02:56,830 --> 00:03:00,680 Normally this would be the URL of a repo out on the network somewhere 54 00:03:00,680 --> 00:03:02,980 which we'll show you how to do later. 55 00:03:02,980 --> 00:03:04,832 But for this demonstration, 56 00:03:04,832 --> 00:03:09,451 we'll just clone from the medals repo in our local directory. 57 00:03:09,451 --> 00:03:13,155 The second argument is the name of the director you want to clone into. 58 00:03:13,155 --> 00:03:14,505 We'll name it my clone. 59 00:03:16,355 --> 00:03:19,785 It will take a moment to clone the repository with all its history and 60 00:03:19,785 --> 00:03:22,995 check out a copy of all the files into the new working directory. 61 00:03:22,995 --> 00:03:27,780 It will show a message when its done and return us to our shell prompt. 62 00:03:27,780 --> 00:03:31,590 If we run ls, we'll see a new myclone directory. 63 00:03:31,590 --> 00:03:34,370 We can change into that with cd myclone. 64 00:03:36,100 --> 00:03:39,360 The slash character following the directory name in the cd 65 00:03:39,360 --> 00:03:41,430 command is optional, by the way. 66 00:03:41,430 --> 00:03:43,870 If we run ls here in the working directory, 67 00:03:43,870 --> 00:03:45,778 we'll see copies of all our files. 68 00:03:45,778 --> 00:03:50,600 Remember ls -a shows all files, even ones that are hidden, 69 00:03:50,600 --> 00:03:53,560 by placing a dot at the start of their names. 70 00:03:53,560 --> 00:03:54,600 If we run it here, 71 00:03:54,600 --> 00:03:58,820 we'll see another .git directory that holds a copy of our repo history. 72 00:03:59,840 --> 00:04:04,350 We can review that copy of the repo history with the git log command. 73 00:04:04,350 --> 00:04:08,060 It will show us the completely history of changes from the original repo 74 00:04:08,060 --> 00:04:09,270 up to the time it was cloned. 75 00:04:10,630 --> 00:04:14,420 Of course whoever is working in the original medals repo was probably going 76 00:04:14,420 --> 00:04:16,200 to keep making changes to it. 77 00:04:16,200 --> 00:04:19,470 And those changes won't show up in our clone unless we find a way to 78 00:04:19,470 --> 00:04:21,165 copy them over. 79 00:04:21,165 --> 00:04:23,170 We'll learn how to do that in the next video.