WEBVTT

0
00:00.590 --> 00:01.040
All right.

1
00:01.040 --> 00:08.830
So whereas in the last lesson, we were looking at local implementations of using Git and Version Control,

2
00:08.840 --> 00:13.460
in this lesson, we're going to talk about how you can create a Remote Repository.

3
00:13.460 --> 00:20.390
So a repository that's hosted on somebody else's server or somebody else's computer by using GitHub.

4
00:20.420 --> 00:25.850
Now, most people would have heard of GitHub and certainly by now you would have used GitHub many

5
00:25.850 --> 00:26.420
times.

6
00:26.420 --> 00:31.640
So if you haven't yet set up an account on GitHub, then this is the time to do it.

7
00:31.640 --> 00:38.660
So head over to github.com and simply fill out this quick form to create an account on GitHub.

8
00:38.750 --> 00:44.660
It's completely free, and all you need to do is just confirm your email so that you can access it.

9
00:45.380 --> 00:48.220
Once you've done that, go ahead and sign in.

10
00:48.230 --> 00:51.410
Once you've signed in, you should be looking at this page.

11
00:51.410 --> 00:57.740
And what we're going to do is we're going to create a repository inside the browser-based GitHub.

12
00:57.740 --> 01:04.590
So if you navigate to this top right corner and click that plus arrow (+), then you can select New repository

13
01:04.860 --> 01:11.820
and I'm going to call my repository, same name, I guess we'll call it, "Story" and let's give it a description.

14
01:11.820 --> 01:15.960
Let's say, "My masterpiece."

15
01:16.840 --> 01:21.730
Now, by default, all repositories that you create on GitHub are Public.

16
01:21.760 --> 01:27.700
That means that anyone can see all of the files inside your saved repository.

17
01:27.820 --> 01:34.480
So everything that you commit to your remote repository or to your GitHub repository will be public.

18
01:34.780 --> 01:38.410
If you don't want that, then you can select Private,

19
01:38.410 --> 01:44.050
but in most cases, if you're not doing anything that's top secret, or if you're not developing technology

20
01:44.050 --> 01:50.740
that is completely brand new, then having a public repository is not such a big problem.

21
01:50.740 --> 01:56.680
And on the other hand as well, you can see loads of other people's public repositories and you can

22
01:56.680 --> 02:01.990
see, for example, how they structure their code, what is their style, and you can see how people

23
02:01.990 --> 02:02.710
do things.

24
02:02.710 --> 02:10.540
For example, on GitHub, there are whole repositories on things like flappy bird. So it's the entire

25
02:10.540 --> 02:17.450
implementation of flappy bird and you can run it or you can also look through their code base to see

26
02:17.450 --> 02:18.680
how they did this.

27
02:19.550 --> 02:26.000
This is the beauty of open-source code, and as you develop in your journey of becoming a developer,

28
02:26.030 --> 02:32.300
then you might find that you want to contribute to other open source projects, help them out a bit

29
02:32.300 --> 02:37.910
and work in a virtual team to try and contribute your knowledge and your programming skills.

30
02:38.210 --> 02:44.050
Okay, so once I've selected public, the next thing is that I'm going to leave this part empty.

31
02:44.060 --> 02:48.200
I'm not going to initialize a README for my repository just yet.

32
02:48.440 --> 02:53.930
The next thing is that I'm going to go ahead and click the big green button and create my repository.

33
02:54.380 --> 03:00.680
Now, you can see that there are two ways that they tell you, you can set up your repository.

34
03:00.710 --> 03:07.760
You can either set it up in GitHub on desktop, their desktop client, which I am not a big fan of,

35
03:07.790 --> 03:13.820
but instead what we're going to do is we're going to use the command line instructions to set up our

36
03:13.820 --> 03:14.720
repository.

37
03:14.720 --> 03:22.250
So we are going to push an existing repository that we've got locally onto this remote repository.

38
03:22.250 --> 03:30.590
And to do that we need to copy the address of our GitHub repository and we're going to use these two

39
03:30.590 --> 03:37.820
lines of code in order to transfer or push our existing local repository from the command line.

40
03:38.000 --> 03:38.450
All right.

41
03:38.450 --> 03:44.720
I'm currently inside my Story directory, which also happens to be the Working directory for this particular

42
03:44.720 --> 03:45.500
project.

43
03:45.500 --> 03:53.870
And here I am going to again take a look at "git log" to see what previous commits we've got. And you can

44
03:53.870 --> 04:00.260
see that we've got two previous commits and I would like to push both of these commits onto GitHub.

45
04:00.830 --> 04:04.970
To do that, the first thing is creating a Remote.

46
04:04.970 --> 04:13.670
So it's telling my Local Git Repository that I've created a Remote Repository somewhere on the internet

47
04:13.670 --> 04:18.140
and I want to transfer all of my commits over there.

48
04:18.140 --> 04:23.380
So the command that we're going to use is, "git remote add origin".

49
04:23.390 --> 04:30.620
Now, origin is simply the name of your remote and you can theoretically call it anything you want.

50
04:30.650 --> 04:38.000
You can call it bacon if you want, but by convention and it's highly recommended that you simply keep

51
04:38.000 --> 04:39.080
the name origin.

52
04:39.080 --> 04:45.980
And the reason is because most programmers are used to the conventional naming, and that means it will

53
04:46.010 --> 04:50.900
be much easier for them to understand what's going on in your project when they have a look at it,

54
04:50.900 --> 04:55.370
instead of you doing something completely different, which will be very surprising and it'll be a lot

55
04:55.400 --> 04:58.160
harder for people to understand what's going on.

56
04:58.250 --> 05:07.430
So, "git remote add origin", and then we're going to paste the URL of our remote repository on GitHub,

57
05:07.430 --> 05:09.650
and then we're going to go ahead and hit Enter.

58
05:10.400 --> 05:18.890
And now that remote is created, so we can push our local repository onto our Remote Repository, which

59
05:18.890 --> 05:20.120
is called origin.

60
05:20.120 --> 05:26.330
So we're going to say, "git push -u origin main".

61
05:26.330 --> 05:34.130
And what this line of code does is that it pushes your local repository to the remote repository using

62
05:34.130 --> 05:41.030
the u flag or the u option, which basically links up your remote and your local repositories.

63
05:41.030 --> 05:44.600
And then we're going to push it towards the remote

64
05:44.600 --> 05:48.950
that's called origin, and we're going to push it to the branch that's called main.

65
05:49.130 --> 05:55.400
The main branch is simply the default branch or the main branch of all of your commits.

66
05:55.400 --> 06:01.160
And later on when we cover branching, then we're going to talk more about what is a main and what is

67
06:01.160 --> 06:01.850
a branch.

68
06:01.850 --> 06:08.000
But for now, we're just saying that we're going to push our local repository onto this origin remote

69
06:08.000 --> 06:10.460
and we're going to push it to the main branch.

70
06:10.460 --> 06:16.310
So let's go ahead and hit Enter. And there's going to be a little bit of work being done

71
06:16.340 --> 06:22.550
in the background, because it's actually going to have to upload your local repository to the remote

72
06:22.550 --> 06:29.570
repository on GitHub servers, and depending on the size of your local repository, this can take various

73
06:29.570 --> 06:30.590
amounts of time.

74
06:31.460 --> 06:38.150
Now, once we see our prompt, so the flashing cursor, or the dollar sign, that means that our push is

75
06:38.150 --> 06:39.140
successful,

76
06:39.140 --> 06:44.740
and as you can see, it says, "branch main set up to track remote branch main from origin."

77
06:44.810 --> 06:51.110
Sounds really confusing, but if you head back over to GitHub and if you're on the same page, all you

78
06:51.110 --> 06:58.160
have to do is hit command R to refresh or just press the refresh button and you can see that all of

79
06:58.160 --> 07:05.540
our files are now hosted on GitHub and it's complete with all of our commit messages.

80
07:05.540 --> 07:13.160
So if you go into Insights, and go into Network, you can actually see our main branch, which currently

81
07:13.160 --> 07:16.260
only has two save points or two commits.

82
07:16.260 --> 07:21.750
And if you hover over them, you can actually see the commit messages of each of these. As you build

83
07:21.750 --> 07:28.800
out your project, as you add more commits either locally or pushing it remotely or probably doing both,

84
07:28.800 --> 07:33.960
then you can see the progress of your files in your GitHub repository.

85
07:33.960 --> 07:41.970
So now you can see all of the code, if it's code file, or in our case, it's just a text file hosted on

86
07:41.970 --> 07:45.240
GitHub and you can point anybody towards this.

87
07:45.240 --> 07:52.020
And there are actually cases where people do a lot of story writing using GitHub just because it's so

88
07:52.020 --> 07:57.840
good at tracking your save points and being able to revert to previous versions in the past.

89
07:57.840 --> 08:05.970
So for example, if you head over back to the main page and you go to your commits, you can see both

90
08:05.970 --> 08:08.370
of those commits when they were committed,

91
08:08.370 --> 08:13.620
and also if you click on it, you can see the changes that were made at those time points.

92
08:13.620 --> 08:19.920
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

93
08:19.920 --> 08:20.610
commit.

94
08:21.000 --> 08:26.880
Previously, we said that we have a Working directory, which is the directory where we initialized git.

95
08:26.910 --> 08:32.940
Then we can push our files to a Staging area where we can pick and choose which files we want to commit.

96
08:32.970 --> 08:40.620
Then once we're ready, then we can commit our files or our save point to our Local repository.

97
08:40.620 --> 08:48.540
So once you've done a few commits, then you actually have this timeline of various commits and this

98
08:48.540 --> 08:50.400
is called your Main Branch.

99
08:50.400 --> 08:58.560
So the main branch is your main branch of commits or save points, and it is sequential, and this is usually

100
08:58.560 --> 09:04.470
where your main progress is saved or committed. Later on,

101
09:04.470 --> 09:09.510
we then introduced this idea of the Remote Repository.

102
09:09.510 --> 09:15.510
The important thing to note is that you can have a local repository completely in parallel with a remote

103
09:15.510 --> 09:21.120
repository check the differences between them, but you can also sync them or push things from your

104
09:21.120 --> 09:23.640
local repository to your remote repository.

105
09:23.640 --> 09:30.450
So in our case, the local repository is the git file that we've got inside our Story directory,

106
09:30.450 --> 09:38.040
and the remote repository is GitHub, which hosts our code and also hosts all of the changes that were

107
09:38.040 --> 09:40.140
made in between the different commits.

108
09:40.140 --> 09:46.560
So we have this main branch of various commits; first commit, second commit, third commit in our local

109
09:46.560 --> 09:47.700
git repository,

110
09:47.700 --> 09:56.010
and when we performed the command "git push", then that effectively pushed all of those commits, all

111
09:56.010 --> 10:03.900
of those various versions and changes, and code pieces to our remote repository on GitHub.

112
10:03.900 --> 10:05.700
So that's what "git push" does.

113
10:05.730 --> 10:11.250
Now in the next lesson, I want to talk about using ".gitignore" and how you can avoid uploading sensitive

114
10:11.250 --> 10:18.570
pieces of information such as API Keys or Passwords to your remote repositories for example, GitHub.

115
10:18.570 --> 10:21.030
So all of that and more on the next lesson.

116
10:21.060 --> 10:21.900
See you there.