WEBVTT 0 00:00.750 --> 00:01.110 All right. 1 00:01.110 --> 00:08.670 So whereas in the last lesson we were looking at local implementations of using Git and version control, 2 00:09.240 --> 00:13.530 in this lesson we're going to talk about how you can create a remote repository, 3 00:13.740 --> 00:20.520 so a repository that's hosted on somebody else's server or somebody else's computer by using GitHub. 4 00:20.790 --> 00:22.740 Now most people would have heard of GitHub 5 00:22.770 --> 00:28.770 and certainly by now you would have used GitHub many times in order to grab the skeleton projects that 6 00:28.770 --> 00:32.330 we provided for some of the tutorials and challenges. 7 00:32.340 --> 00:37.490 So if you haven't yet set up an account on GitHub then this is the time to do it. 8 00:37.590 --> 00:44.560 So head over to github.com and simply fill out this quick form to create an account on GitHub. 9 00:44.580 --> 00:51.430 So it's completely free and all you need to do is just confirm your email so that you can access it. 10 00:51.600 --> 00:54.200 Once you've done that go ahead and sign in. 11 00:54.210 --> 00:59.580 So once you've signed in you should be looking at this page and all we're going to do is we're going 12 00:59.580 --> 01:04.090 to create a repository inside the browser based GitHub. 13 01:04.290 --> 01:10.480 So if you navigate to this top right corner and click that plus arrow, then you can select new repository. 14 01:11.370 --> 01:13.340 And I'm going to call my repository 15 01:13.620 --> 01:14.310 same name 16 01:14.310 --> 01:18.000 I guess we'll call that story. And let's give it a description. 17 01:18.010 --> 01:28.080 Let's say 'My masterpiece.' Now by default all repositories that you create on GitHub are public. 18 01:28.290 --> 01:34.380 That means that anyone can see all of the files inside your save repository. 19 01:34.380 --> 01:41.620 So everything that you commit to your remote repository or to your GitHub repository will be public. 20 01:41.700 --> 01:48.110 So if you don't want that then you can select private which requires a subscription on GitHub. 21 01:48.300 --> 01:53.730 But in most cases if you're not doing anything that's top secret or if you're not developing technology 22 01:53.730 --> 02:00.430 that is completely brand new, then having a public repository is not such a big problem. 23 02:00.660 --> 02:06.510 And on the other hand as well you can see loads of other people's public repository and you can see 24 02:06.510 --> 02:08.930 for example how they structure that code, 25 02:09.000 --> 02:10.660 what is their style 26 02:10.860 --> 02:12.770 and you can see how people do things. 27 02:12.900 --> 02:19.950 So for example on GitHub there are whole repositories on things like swift flappy bird. 28 02:19.950 --> 02:27.680 So it's the entire implementation of flappy bird in Swift and you can run it in a simulator or 29 02:27.720 --> 02:35.200 you can also look through their code base to see how they did this. So this is the beauty of open source 30 02:35.200 --> 02:35.770 code. 31 02:35.830 --> 02:43.270 And as you develop in your journey of becoming a developer then you might find that you want to contribute 32 02:43.390 --> 02:45.310 to other open source projects, 33 02:45.430 --> 02:51.340 help them out a bit and work in a virtual team to try and contribute your knowledge and your programming 34 02:51.340 --> 02:52.450 skills. 35 02:52.480 --> 02:58.860 Oay. So now once I've selected public, the next thing is that I'm going to leave this part empty. 36 02:58.960 --> 03:03.000 I'm not going to initialize a read me from my repository just yet. 37 03:03.340 --> 03:09.200 So the next thing is I'm going to go ahead and click the big green button and create my repository. 38 03:09.670 --> 03:16.130 So now you can see that there are two ways that they tell you you can set up your repository. 39 03:16.360 --> 03:23.830 You can either set it up in GitHub for Mac on desktop their desktop client which I am not a big fan 40 03:23.830 --> 03:24.110 of. 41 03:24.160 --> 03:30.100 But instead what we're going to do is we're going to use the command line instructions to set up our 42 03:30.100 --> 03:31.050 repository. 43 03:31.240 --> 03:38.860 So we are going to push an existing repository that we've got locally onto this remote repository and 44 03:38.860 --> 03:45.230 to do that we need to copy the address of our GitHub repository 45 03:45.610 --> 03:53.230 and we're going to use these two lines of code in order to transfer or push our existing local repository 46 03:53.500 --> 03:54.730 from the command line. 47 03:54.730 --> 04:00.670 All right. So I'm currently inside my story directory which also happens to be the working directory 48 04:00.940 --> 04:02.530 for this particular project. 49 04:02.860 --> 04:10.450 And here I am going to again take a look at git log to see what previous commits we've got. 50 04:10.600 --> 04:12.990 And you can see that we've got two previous commits. 51 04:13.060 --> 04:17.750 And I would like to push both of these commits on to GitHub. 52 04:18.070 --> 04:26.050 So to do that the first thing is creating a remote. So it's telling my local Git repository that I've 53 04:26.050 --> 04:35.140 created a remote repository somewhere on the Internet and I want to transfer all of my commits over 54 04:35.140 --> 04:35.530 there. 55 04:35.710 --> 04:40.830 So the command that we're going to use is git remote add origin. 56 04:41.020 --> 04:48.130 Now origin is simply the name of your remote and you can theoretically call it anything you want. 57 04:48.130 --> 04:50.430 You can call it bacon if you want. 58 04:50.710 --> 04:57.880 But by convention and it's highly recommended that you simply keep the name origin and the reason is 59 04:57.880 --> 05:04.840 because most programs are used to the conventional naming and that means it will be much easier for 60 05:04.840 --> 05:09.580 them to understand what's going on in your projects when they have a look at it instead of you doing 61 05:09.580 --> 05:14.500 something completely different which will be very surprising and will be a lot harder for people to 62 05:14.500 --> 05:16.080 understand what's going on. 63 05:16.390 --> 05:24.760 So gid remote add origin and then we're going to paste the URL of our remote repository on Git 64 05:24.760 --> 05:27.830 Hub and then we're going to go ahead and hit enter. 65 05:28.630 --> 05:36.880 And now that remote is created so we can push our local repository onto our remote repository which is 66 05:36.880 --> 05:38.150 called origin. 67 05:38.290 --> 05:44.920 So we're going to say git push -u origin master. 68 05:45.220 --> 05:52.840 And what this line of code does is that it pushes your local repository to the remote repository using 69 05:52.840 --> 06:01.180 the u flag or the u option which basically links up your remote and your local repositories. And then 70 06:01.360 --> 06:06.610 we're going to push it towards the remote that's called origin and we're going to push it to the branch 71 06:06.640 --> 06:08.650 that's called master. 72 06:08.650 --> 06:15.410 So the master branch is simply the default branch or the main branch of all of your commits. 73 06:15.520 --> 06:21.340 And later on when we cover branching, then we're going to talk more about what is a master and what is 74 06:21.340 --> 06:22.130 a branch. 75 06:22.150 --> 06:28.750 But for now we're just saying that we're going to push our local repository onto this origin remote and 76 06:28.780 --> 06:30.810 we're going to push it to the master branch. 77 06:30.880 --> 06:33.140 So let's go ahead and hit enter. 78 06:34.030 --> 06:38.680 And there's going to be a little bit of work being done in the background because it's actually going 79 06:38.680 --> 06:46.450 to have to upload your local repository to the remote repository on GitHub servers and depending on 80 06:46.450 --> 06:52.320 the size of your local repository this can take various amounts of time. 81 06:52.330 --> 06:54.570 So now once we see our prompt, 82 06:54.610 --> 07:00.150 so the flashing cursor or the dollar sign, that means our push is successful. 83 07:00.490 --> 07:06.350 And as you can see it says, 'Branch master set up to track remote branch master from origin' 84 07:06.370 --> 07:12.670 Sounds really confusing but if you head back over to GitHub and if you're on the same page, all you 85 07:12.670 --> 07:19.720 have to do is hit COMMAND + R to refresh or just press the refresh button and you can see that all of 86 07:19.720 --> 07:27.370 our files are now hosted on GitHub and it's complete with all of our commit messages. 87 07:27.400 --> 07:35.810 So if you go to insights, graphs and go into network, you can actually see our mass the branch which currently 88 07:35.870 --> 07:42.290 only has two save points or to commits. If you hover over them you can actually see the commit messages 89 07:42.320 --> 07:43.640 of each of these. 90 07:43.670 --> 07:50.720 So as you build out your project, as you add more commits either locally or pushing it remotely or probably 91 07:50.720 --> 07:56.870 doing both, then you can see the progress of your files in your GitHub repository. 92 07:56.870 --> 08:05.400 So now you can see all of the code if it's code file or in all cases just a text file, hosted on Git 93 08:05.410 --> 08:08.510 Hub and you can point anybody towards this. 94 08:08.570 --> 08:14.780 And there are actually cases where people do a lot of story writing using GitHub just because it's 95 08:14.780 --> 08:22.100 so good at tracking your save points and being able to revert to previous versions in the past. 96 08:22.100 --> 08:30.110 So for example, if you head over back to the main page and you go to your commits, you can see both of 97 08:30.110 --> 08:32.520 those commits when they were committed 98 08:32.690 --> 08:38.540 and also if you click on it you can see the version-- you can see the changes that were made at those 99 08:38.540 --> 08:39.220 time points. 100 08:39.260 --> 08:45.500 So if we have a look at chapter 1 you can see this is all we had at the point when we made our first 101 08:45.500 --> 08:46.250 commit. 102 08:46.250 --> 08:52.340 So previously we said that we have a working directory which is the directory where we initialized Git. 103 08:52.550 --> 08:58.380 Then we can push our files to a staging area where we can pick and choose which files we want to commit. 104 08:58.520 --> 09:06.560 Then once we're ready then we can commit our files or save safe point to our local repository. 105 09:06.560 --> 09:13.130 So once you've done a few commits then you actually have this timeline of various commits. 106 09:13.340 --> 09:16.540 And this is called your master branch. 107 09:16.610 --> 09:23.840 So the master branch is your main branch of commits or save points and it is sequential. 108 09:23.840 --> 09:29.900 And this is usually where your main progress is saved or committed. 109 09:29.900 --> 09:36.240 Now later on we then introduced this idea of the remote repository. 110 09:36.260 --> 09:42.200 The important thing to note is that you can have a local repository completely in parallel with a remote 111 09:42.200 --> 09:43.040 repository. 112 09:43.100 --> 09:49.100 Check the differences between them but you can also sync them so that they all the same. 113 09:49.100 --> 09:54.450 But you can also sync them or push things from your local repository to your remote posturing. 114 09:54.560 --> 10:02.300 So in our case, the local repository is the git file that we've got inside our story directory and the 115 10:02.300 --> 10:10.460 remote repository is the git directory that we've got inside our story directory and the remote repository 116 10:10.580 --> 10:17.750 is GitHub which hosts our code and also host all of the changes that were made in between the different 117 10:17.750 --> 10:18.290 committees. 118 10:18.320 --> 10:24.650 So we have this master branch of various commits first commit, second commit, third commit in our local 119 10:24.680 --> 10:32.750 Git repository and when we performed the command git to push, then that effectively pushed all of those 120 10:32.810 --> 10:42.290 commits, all of those various versions and changes and code pieces to our remote repository on GitHub. 121 10:42.290 --> 10:45.030 So that's what Git pushed us. Now in the next lesson 122 10:45.050 --> 10:50.630 I want to talk about using git ignore and how you can avoid uploading sensitive pieces of information 123 10:50.900 --> 10:56.690 such as API keys or passwords to your remote repositories for example GitHub. 124 10:56.780 --> 10:59.280 So all of that and more on the next lesson, 125 10:59.300 --> 10:59.840 see you there.