1 00:00:00,170 --> 00:00:03,600 We've shown you how to make repo clones so you can actively work in, and 2 00:00:03,600 --> 00:00:05,980 how to pull commits from those clones. 3 00:00:05,980 --> 00:00:09,570 But that's mainly useful while you're learning how git works. 4 00:00:09,570 --> 00:00:13,960 It's far more common to host a central repo on a code hosting service. 5 00:00:13,960 --> 00:00:16,610 GitHub is the most popular git service. 6 00:00:16,610 --> 00:00:21,010 Other alternatives that work similarly include BitBucket and GitLab. 7 00:00:21,010 --> 00:00:23,760 See that teacher's notes for info on those. 8 00:00:23,760 --> 00:00:27,380 After setting up a repo and making some commits on your local machine, 9 00:00:27,380 --> 00:00:31,300 you create a new empty repo on a hosting services server. 10 00:00:31,300 --> 00:00:34,435 Then you add the new repo as a remote on your local repo and 11 00:00:34,435 --> 00:00:35,918 push your commits there. 12 00:00:35,918 --> 00:00:39,846 Other developers can clone this central hosted to their machines. 13 00:00:39,846 --> 00:00:43,879 As you make more commits on your local repo, you can push them up to the central 14 00:00:43,879 --> 00:00:47,978 repo, other developers can then pull the commits down to their cloned repos so 15 00:00:47,978 --> 00:00:49,810 they're up to date. 16 00:00:49,810 --> 00:00:54,700 Let's create a repo on GitHub so we can push our medals repository code to it. 17 00:00:54,700 --> 00:00:58,110 To create a repo on GitHub, you'll need to create an account. 18 00:00:58,110 --> 00:01:01,850 There are two kinds of accounts on GitHub, free and paid. 19 00:01:01,850 --> 00:01:06,660 The paid plans let you host private repos, where no one else can see the code. 20 00:01:06,660 --> 00:01:10,300 These are appropriate for companies working on proprietary code. 21 00:01:10,300 --> 00:01:12,830 The free plans can only create public repos, 22 00:01:12,830 --> 00:01:16,390 where anyone can browse the code on the web or clone it using git. 23 00:01:16,390 --> 00:01:20,930 But for open source projects, this is actually preferable to a private repo. 24 00:01:20,930 --> 00:01:23,870 So a free plan may work just fine for your needs. 25 00:01:23,870 --> 00:01:27,040 The type of account you create is up to you, either one will work for 26 00:01:27,040 --> 00:01:29,220 following along with this video. 27 00:01:29,220 --> 00:01:34,080 The sign up process is pretty simple, just visit github.com in your web browser and 28 00:01:34,080 --> 00:01:36,040 click the sign up link. 29 00:01:36,040 --> 00:01:37,850 Then follow the directions. 30 00:01:37,850 --> 00:01:39,000 Websites change, so 31 00:01:39,000 --> 00:01:42,710 what you see at github.com may not exactly match what's shown here. 32 00:01:42,710 --> 00:01:45,590 But the basic process should be the same. 33 00:01:45,590 --> 00:01:48,180 If you encounter any trouble while setting up an account or 34 00:01:48,180 --> 00:01:51,550 your first repo check the teacher's notes for help. 35 00:01:51,550 --> 00:01:55,010 Once you've signed up, we need to create a new repo on GitHub. 36 00:01:55,010 --> 00:01:59,370 From any page on github.com there should be a menu with a New repository link. 37 00:02:01,170 --> 00:02:05,370 Click that, we'll be asked to enter a repository name. 38 00:02:05,370 --> 00:02:07,680 Ideally repo names are all lowercase, and 39 00:02:07,680 --> 00:02:10,970 if there are multiple words they'll be separated with dashes. 40 00:02:10,970 --> 00:02:15,510 We can use any name we want, but let's just use medals, after all, 41 00:02:15,510 --> 00:02:18,520 that matches the name of our local copy of the repo. 42 00:02:18,520 --> 00:02:25,950 We'll also enter a quick description of the repo, website for medals store. 43 00:02:25,950 --> 00:02:29,080 Now you can choose whether to make the repo public or private. 44 00:02:29,080 --> 00:02:31,800 Unless you have a paid account, you'll want to leave it set to public. 45 00:02:33,400 --> 00:02:38,460 You may see a check box allowing you to initialize this repository with a README. 46 00:02:38,460 --> 00:02:42,280 But it says to skip this step if you're importing an existing repository, 47 00:02:42,280 --> 00:02:45,210 which we are, so we'll leave that box unchecked. 48 00:02:45,210 --> 00:02:48,220 There may also be options to add a git ignore file or 49 00:02:48,220 --> 00:02:51,280 license file, leave those set to none. 50 00:02:51,280 --> 00:02:54,130 When you're ready, click the button to create a repository. 51 00:02:55,770 --> 00:02:58,960 You'll be taken to the web page for your new repository. 52 00:02:58,960 --> 00:03:02,900 This is the URL where the public will go to view your project source code in their 53 00:03:02,900 --> 00:03:04,710 web browsers. 54 00:03:04,710 --> 00:03:07,150 There's no code to view here right now though. 55 00:03:07,150 --> 00:03:10,100 Instead, you'll probably see a set of tips on getting started. 56 00:03:11,160 --> 00:03:14,670 These include shell commands that been customized to work for your repo. 57 00:03:15,940 --> 00:03:19,730 There's a section for use if you've done this kind of thing before. 58 00:03:19,730 --> 00:03:24,108 There are two protocol options here, SSH and HTTPS. 59 00:03:26,087 --> 00:03:27,381 Notice that the URLs and 60 00:03:27,381 --> 00:03:31,310 all the commands change depending on which option you click. 61 00:03:31,310 --> 00:03:34,276 To get started, we wants to select HTTPS. 62 00:03:34,276 --> 00:03:37,190 Although you might want to switch to SSH later. 63 00:03:37,190 --> 00:03:40,460 See the teacher's notes for more info on these options. 64 00:03:40,460 --> 00:03:44,720 There's a section that create a new repository, we already have a repository. 65 00:03:44,720 --> 00:03:48,170 So we don't need that, we're going to want the section two, 66 00:03:48,170 --> 00:03:50,950 push an existing repository from the command line. 67 00:03:52,650 --> 00:03:54,040 Let's go to our console and 68 00:03:54,040 --> 00:03:58,830 run the command they suggest, the first is a git remote add command. 69 00:04:00,440 --> 00:04:04,850 As the GitHub instructions suggest, will give the remote repo a name of origin. 70 00:04:06,110 --> 00:04:09,660 This is the same name that would have been setup by default if we had cloned our 71 00:04:09,660 --> 00:04:12,120 local repo from the GitHub repo. 72 00:04:12,120 --> 00:04:15,770 Now we need the second argument, the URL of the remote repo. 73 00:04:15,770 --> 00:04:18,920 In the previous video, we just used the path of another directory. 74 00:04:18,920 --> 00:04:21,980 But here we're going to use the URL provided by GitHub, so 75 00:04:21,980 --> 00:04:23,900 that git can connect to it over the Internet. 76 00:04:25,030 --> 00:04:28,194 We'll just copy the URL from the command shown in our browser. 77 00:04:31,221 --> 00:04:33,060 Then we'll paste it into the terminal. 78 00:04:35,000 --> 00:04:37,870 Once all that's typed in, press Enter to add the command, and 79 00:04:37,870 --> 00:04:40,540 it will add the GitHub repository as a remote repo. 80 00:04:42,120 --> 00:04:47,770 The second command, GitHub recommends we run is a new command, git push. 81 00:04:47,770 --> 00:04:52,990 Whereas the git pull command pulls changes from a remote repo into your local repo, 82 00:04:52,990 --> 00:04:58,220 the git push command pushes changes from your local repo into a remote repo. 83 00:04:58,220 --> 00:05:00,830 Git pull gets changes made by others, 84 00:05:00,830 --> 00:05:04,420 git push shares changes you've made with others. 85 00:05:04,420 --> 00:05:08,070 Because git push makes changes of the remote repo without warning, 86 00:05:08,070 --> 00:05:11,740 it's generally not used with clone repos that people work in. 87 00:05:11,740 --> 00:05:16,040 Instead, it's used with repos that are hosted on services like GitHub. 88 00:05:16,040 --> 00:05:19,250 GitHub recommends a few arguments to git push as well. 89 00:05:19,250 --> 00:05:22,450 First is the -u command line option. 90 00:05:22,450 --> 00:05:26,460 The u stands for upstream as in set up stream. 91 00:05:26,460 --> 00:05:31,090 Just as a source of all the water in a river lies upstream of wherever you are, 92 00:05:31,090 --> 00:05:34,490 upstream is a term that refers to a remote repo that 93 00:05:34,490 --> 00:05:37,280 is the source of the code in this local repo. 94 00:05:37,280 --> 00:05:42,140 The -u or set upstream option, means that you want git to remember the repo and 95 00:05:42,140 --> 00:05:43,790 branch you're about to specify. 96 00:05:43,790 --> 00:05:49,580 And make all future git push commands push to that repo and branch by default. 97 00:05:49,580 --> 00:05:54,770 That way you won't have to specify a repo and branch each time you run git push. 98 00:05:54,770 --> 00:05:58,740 The next two commands need to actually specify that default repo and branch. 99 00:05:58,740 --> 00:06:04,740 So, we'll use a repo of origin and we'll specify the only branch that 100 00:06:04,740 --> 00:06:09,340 exists in the remote repo, the one branch that gets created by default, master. 101 00:06:11,330 --> 00:06:15,980 When we run the command, because we used an HTTPS URL for the remote repo, 102 00:06:15,980 --> 00:06:17,830 we'll be prompted for a user name. 103 00:06:18,950 --> 00:06:21,792 So I'll enter the name that I used when signing up for an account, 104 00:06:21,792 --> 00:06:27,000 this username I'm entering won't work for you, of course. 105 00:06:27,000 --> 00:06:30,220 You should enter the username you chose when setting up your GitHub account. 106 00:06:32,020 --> 00:06:33,910 Then we'll be prompted for a password. 107 00:06:33,910 --> 00:06:37,770 Again, enter the password you chose when setting up your account. 108 00:06:37,770 --> 00:06:38,810 If everything works, 109 00:06:38,810 --> 00:06:42,630 you'll see several messages as git uploads our commits to the remote repo. 110 00:06:43,740 --> 00:06:46,731 Now let's go back to our web browser and refresh the page. 111 00:06:49,814 --> 00:06:52,530 We'll see the GitHub repo has been updated. 112 00:06:52,530 --> 00:06:55,190 All of our files are here along with other information. 113 00:06:56,240 --> 00:06:58,330 We'll explore more of that in the next video. 114 00:06:59,840 --> 00:07:02,400 Let me show you something back on our console. 115 00:07:02,400 --> 00:07:04,230 Notice the message here at the bottom, 116 00:07:04,230 --> 00:07:07,810 branch master set up to track remote branch master from origin. 117 00:07:09,130 --> 00:07:13,092 That's there because we passed the -u option to the git push command. 118 00:07:13,092 --> 00:07:17,280 It means you won't need to specify the repo or branch names from now on. 119 00:07:17,280 --> 00:07:20,269 You'll be able to just type git push by itself, 120 00:07:20,269 --> 00:07:22,829 you'll still need to enter a user name. 121 00:07:25,929 --> 00:07:32,560 And a password, and it will push to the origin repo's master branch by default. 122 00:07:32,560 --> 00:07:35,980 In this case since we haven't made any new commits it will just say 123 00:07:35,980 --> 00:07:37,510 everything up to date. 124 00:07:37,510 --> 00:07:39,740 By the way, if you'd rather not type a username and 125 00:07:39,740 --> 00:07:43,800 password each time you push, see the teacher's notes for some tips. 126 00:07:43,800 --> 00:07:46,540 Now we know how to push our changes up to GitHub, but 127 00:07:46,540 --> 00:07:48,770 what exactly does that do for us? 128 00:07:48,770 --> 00:07:50,260 We'll show you in the next video.