WEBVTT

0
00:00.170 --> 00:05.780
In the last few lessons, we looked at implementing source control locally, using the command line

1
00:05.780 --> 00:08.560
and also remotely using GitHub.

2
00:08.570 --> 00:15.530
So now I want to take you a little bit further and I want to talk about collaboration using remote repositories

3
00:15.530 --> 00:23.960
and GitHub because this is one of the best ways to start working in a team of programmers and to contribute

4
00:23.960 --> 00:26.540
your skills to open source projects.

5
00:26.540 --> 00:32.270
So we've seen all of these four areas the Working Directory, the Staging area, the Local Repository

6
00:32.270 --> 00:34.220
as well as the Remote Repository,

7
00:34.220 --> 00:38.060
and you should be pretty familiar with all four of these areas by now.

8
00:38.090 --> 00:45.620
Now in the next scenario, let's shift over to just look at the Local and Remote Repository that you

9
00:45.620 --> 00:46.220
own.

10
00:46.250 --> 00:47.750
Let's say that,

11
00:47.750 --> 00:51.200
Angela, so myself, I own this repository.

12
00:51.200 --> 00:56.270
I created it locally and then I pushed it to my remote repository on GitHub.

13
00:56.360 --> 01:02.340
Now let's say that I have an evil twin who's called, I don't know,

14
01:02.610 --> 01:04.740
Bangela. That's a terrible name.

15
01:05.520 --> 01:10.010
Let's say that she also wanted to make changes to my repository.

16
01:10.020 --> 01:16.020
She's looking at my code base and you know, she wants to add some features or fix some bugs or do something.

17
01:16.650 --> 01:20.850
Because I own this remote repository over here,

18
01:20.850 --> 01:28.050
in order for her to work on it, she could make a copy of it that exists on her GitHub account.

19
01:28.080 --> 01:30.620
Remember, this is different from "git clone".

20
01:30.630 --> 01:38.610
Git clone is just grabbing at the entirety of the repository and then cloning it to your local work

21
01:38.610 --> 01:39.360
environment.

22
01:39.390 --> 01:45.300
Now, in this case, we're basically just copying a repository that's hosted on GitHub and we're keeping

23
01:45.300 --> 01:49.740
the copy under our own GitHub account where we can make changes to it.

24
01:49.740 --> 01:53.850
So this in terms of GitHub lingo is called Forking.

25
01:53.850 --> 01:58.590
Now once you've forked a remote repository, then you now own it.

26
01:58.590 --> 02:05.160
You have full permissions to do whatever it is that you like with this copy of the repository, because

27
02:05.160 --> 02:12.300
as you can imagine, it would be pretty crazy if everybody could modify your source code on all of your

28
02:12.300 --> 02:18.090
open source repositories because, you know, it would lead to maybe amateurs changing all sorts of

29
02:18.090 --> 02:24.450
things that you don't want them to or, you know, people making features that are incompatible with

30
02:24.450 --> 02:25.830
what you've got already.

31
02:25.830 --> 02:30.600
Basically, you would only give people who you have a trusting relationship with, write

32
02:30.600 --> 02:32.700
access, to your remote repository.

33
02:32.700 --> 02:39.060
So say if you worked within a team and you're all working on a product, then everybody in the team

34
02:39.060 --> 02:45.390
probably has both read and write permissions on a single remote repository and that way they can "git

35
02:45.390 --> 02:51.420
clone" and work on it locally and then push it and resolve any sort of conflicts that way,

36
02:51.420 --> 02:55.890
but you don't want anybody on the Internet having those kind of permissions.

37
02:55.890 --> 03:00.000
So how do you implement this kind of open source collaboration then?

38
03:00.000 --> 03:03.480
Well, it's through Forking and making Pull requests.

39
03:04.470 --> 03:09.510
So now let's say that evil Angela, Bangela has forked my repository.

40
03:09.510 --> 03:17.940
So on her GitHub account, she now owns a copy of my repository and from this point she can then clone

41
03:17.940 --> 03:20.910
that repository to work on it locally.

42
03:20.910 --> 03:27.420
And if she decides to add some features to it, maybe, you know, improve the code base or add some

43
03:27.420 --> 03:33.390
more code or do something crazy or whatever it is that she wants, then after she's happy with that

44
03:33.390 --> 03:39.090
and she's committed those changes, then she can push it to her remote repository.

45
03:39.090 --> 03:46.680
And then if she wants me or good Angela to incorporate those changes that she made, then her only option

46
03:46.680 --> 03:49.140
is to make a "Pull request",

47
03:49.140 --> 03:55.560
if she is not within that trusted pool of people who all have read and write access to my remote repository.

48
03:55.560 --> 04:00.900
So say if she only has read access, then she would have to make a Pull request.

49
04:00.900 --> 04:03.270
And it's almost like making a suggestion.

50
04:03.270 --> 04:06.450
Here are some suggested changes that I've been working on,

51
04:06.450 --> 04:07.740
what do you think about it?

52
04:07.740 --> 04:13.080
If you okay it, then please, you know, merge it to your remote repository.

53
04:13.110 --> 04:19.470
The reason why it's called a Pull request and not a push request is because the person who has the write

54
04:19.470 --> 04:21.150
permission to the repository,

55
04:21.150 --> 04:29.100
so I have write permission to my own remote repository, which has been forked and duplicated by, you

56
04:29.100 --> 04:30.600
know, my evil twin.

57
04:30.600 --> 04:37.170
If she wants to incorporate those changes, then I have the deciding vote so I can review those changes

58
04:37.170 --> 04:40.980
and I can pull the changes over.

59
04:40.980 --> 04:47.520
So it's not a push because you don't own the rights to the remote repository that you're trying to push

60
04:47.520 --> 04:48.150
to.

61
04:48.710 --> 04:54.680
In this case, if I decide after a code review that actually those features that she added were pretty

62
04:54.680 --> 05:00.980
great and it seems compatible with my code so far and doesn't break anything, then I would approve

63
05:00.980 --> 05:11.060
the pull request and merge her repository with my own, so the changes will be reflected in a new commit.

64
05:11.060 --> 05:13.400
So let's take a look at this in action.

65
05:14.880 --> 05:18.630
So here we've got our original Story repository.

66
05:18.630 --> 05:24.990
So this is a remote repository, remember, because it's hosted online on GitHub and we've got a number

67
05:24.990 --> 05:31.880
of commits and we've been doing some modifications and writing to write our storyline.

68
05:31.890 --> 05:35.160
Now I'm going to log out of my account.

69
05:35.160 --> 05:42.210
So that was the account that created the Story and then I'm going to sign in using a different account.

70
05:42.210 --> 05:46.080
So right now I'm signed in to a different GitHub account.

71
05:46.350 --> 05:53.310
This account is named "gilfoyleismyothername", and now I'm going to search for that repository.

72
05:53.340 --> 05:57.600
So I found the Story repository by the user angelabauer.

73
05:57.600 --> 05:59.850
So that was the one that we saw earlier on.

74
05:59.850 --> 06:06.060
So I'm going to go into this repository, and you can see that all of these lines and files are publicly

75
06:06.060 --> 06:12.510
visible and you can read through all of it even though you are now not signed in to the account that

76
06:12.510 --> 06:19.300
created this repository. From here, what I'm going to do is I'm going to Fork this repository.

77
06:20.200 --> 06:28.510
As we mentioned before, forking is simply making a copy or a duplicate of a remote repository and putting

78
06:28.510 --> 06:31.450
it under your own GitHub account.

79
06:31.480 --> 06:39.400
You can see this user that I've created is called gilfoyleismyothername, and now I have this repository

80
06:39.400 --> 06:46.120
under my own username, so I've made a copy of it and you can see it's exactly the same as before.

81
06:46.120 --> 06:50.590
Everything's been copied over, including all of the previous commits that were made.

82
06:50.860 --> 06:54.220
So from here I'm going to make some changes.

83
06:54.220 --> 06:58.720
So let's maybe change one of these storylines.

84
06:59.410 --> 07:01.690
So let's change chapter 4.

85
07:04.470 --> 07:11.580
So let's say that this other user, this other person has some suggested improvements to my code, or

86
07:11.580 --> 07:13.330
in this case, to my writing.

87
07:13.350 --> 07:19.740
They're still keeping the spirit of the original repository alive because we are now converting into

88
07:19.740 --> 07:22.530
a space-theme or an alien-theme.

89
07:22.680 --> 07:29.610
So I've made my changes to chapter4, and I'm going to commit those changes saying, "Add more space-

90
07:29.610 --> 07:34.090
themes to chapter 4."

91
07:34.110 --> 07:37.230
So that's what I did, and I'm going to commit to the master branch.

92
07:37.230 --> 07:43.440
So this is the master branch of my own forked copy of the Story repository.

93
07:43.440 --> 07:50.820
So once I commit those changes, then we can view what it currently looks like under the Graphs.

94
07:50.920 --> 07:54.060
If we have a look at the Network,

95
07:55.020 --> 08:03.720
you can see that this is the point where I forked the story repository and that commit was created by

96
08:03.720 --> 08:08.140
Angela Yu, which basically merged this branch to the master branch.

97
08:08.140 --> 08:09.220
So we did that

98
08:09.220 --> 08:10.090
two lessons back,

99
08:10.090 --> 08:11.050
if you remember.

100
08:11.470 --> 08:15.580
The latest commit though, is made by this current user,

101
08:15.610 --> 08:23.290
gilfoyleismyothername, and you can see that I've added it to the master branch of my forked copy

102
08:23.290 --> 08:24.700
of that repository.

103
08:24.840 --> 08:34.570
Say, if I now open up a incognito window and I log back in to the Angela account and go over to that

104
08:34.570 --> 08:43.330
Story repository, you can see that if I have a look inside my Graphs go into Network that that latest

105
08:43.330 --> 08:46.720
change, it's not reflected on my master branch.

106
08:46.750 --> 08:54.790
It's showing up as a separate branch made by gilfoylismyothername and you can see the members

107
08:54.790 --> 08:56.800
who have forked your repository.

108
08:57.080 --> 09:03.910
This is a great way of collaborating because you can have contributors, make edits or add new features

109
09:03.910 --> 09:07.990
to your pre-existing code base or repository.

110
09:08.200 --> 09:14.050
And now what I can do if I head back to the Gilfoyle account,

111
09:14.710 --> 09:20.530
so I'm just going to flip through these two so that you can see, right now I'm inside the Gilfoyle account,

112
09:20.530 --> 09:23.890
and this is the angelabauer account.

113
09:24.190 --> 09:29.830
Now, under the Gilfoyle account, what I can do is I can make a Pull request.

114
09:29.860 --> 09:31.630
We can do that here

115
09:31.660 --> 09:34.180
and you can see that it's able to merge.

116
09:34.390 --> 09:36.550
And these are the changes.

117
09:36.550 --> 09:40.360
So swapping that word for that word, swapping that word for that phrase.

118
09:40.750 --> 09:49.270
Now, all I have to do is hit Create Pull request and tell the original author, which is Angela

119
09:49.270 --> 09:58.600
Bauer, what I've done, why I think my modifications or my features are worthy to be merged with the

120
09:58.600 --> 10:00.190
original repository.

121
10:00.190 --> 10:01.090
And you know,

122
10:01.090 --> 10:02.080
any other notes, right?

123
10:02.080 --> 10:04.030
Any other comments that I have.

124
10:04.540 --> 10:06.100
Let's just say...

125
10:09.480 --> 10:10.860
Always helps to be complimentary.

126
10:10.890 --> 10:14.580
Now, let's go ahead and create a Pull request.

127
10:17.130 --> 10:18.900
The pull request is done,

128
10:18.900 --> 10:27.600
but if we have a look back into the Story repository, you can see that those changes are not made right?

129
10:27.600 --> 10:30.180
It's because I don't own this repository.

130
10:30.180 --> 10:36.420
I don't have write access, only have read access as a member of the general public and not a member

131
10:36.420 --> 10:38.950
of the trusted inner circle.

132
10:38.970 --> 10:42.690
So I can only suggest my changes.

133
10:43.110 --> 10:48.870
If we head over back to the angelabauer account who owns this repository.

134
10:49.620 --> 10:56.120
Now, if I have a look under Pull requests, I've got a brand new Pull request, right?

135
10:56.130 --> 11:01.920
So it previously was 0, but now I have 1 and it's showing as 1 Open Pull request.

136
11:01.920 --> 11:04.800
And this is added a minute ago by

137
11:04.800 --> 11:12.390
Gilfoyle and if I look at it, I can see why he thinks that this modification is necessary and what

138
11:12.390 --> 11:14.040
were his commit message.

139
11:14.040 --> 11:21.250
And I can also take a look at the commits that he made and compare the differences.

140
11:21.250 --> 11:24.040
So review those changes.

141
11:24.720 --> 11:27.870
So I could say something like, great job,

142
11:28.470 --> 11:31.740
Gilfoyle. And I can submit this feedback to

143
11:31.740 --> 11:35.700
Gilfoyle and approve merging these changes.

144
11:37.880 --> 11:50.030
Now, all I have to do is hit Merge pull request and maybe add a, "Merged from Gilfoyle's modifications

145
11:50.030 --> 11:52.310
to chapter 4."

146
11:52.850 --> 11:56.420
Okay, so let's go ahead and confirm the merge.

147
11:57.350 --> 12:03.290
And now you can see that that commit is added to angelabauer, master.

148
12:03.320 --> 12:06.800
So if I have a look inside my Graphs now,

149
12:09.230 --> 12:15.110
you can see that the latest commit was my merge and you can see where it came from.

150
12:15.110 --> 12:21.230
It came from a fork made by Gilfoyle, which shows up as a separate branch, and then it got merged

151
12:21.230 --> 12:24.230
back into the main branch of the main repository.

152
12:24.440 --> 12:31.340
So some people use GitHub purely as version control for their own projects and use some of the features

153
12:31.340 --> 12:33.560
that we discussed in previous lessons,

154
12:33.560 --> 12:43.610
but there's also a huge community of awesome coders on here who have created really brilliant projects

155
12:43.610 --> 12:51.200
and if you can see ways of improving it or contributing to it, then it's a great way of starting to

156
12:51.200 --> 12:57.590
learn how to work in a team of programmers, which is a really essential skill when you're working for

157
12:57.590 --> 12:59.180
a startup or for a company.

158
12:59.780 --> 13:08.180
So, for example, if we have a look at the Alamofire repository, if you have a look at the contributions,

159
13:08.180 --> 13:15.090
you can see that there have been loads and loads of other users who have looked at the code and done

160
13:15.090 --> 13:22.110
things, you know, or made suggestions, and to steadily improve this framework that, you know, everybody

161
13:22.110 --> 13:24.000
else is benefiting off, right?

162
13:24.000 --> 13:32.130
You can see that a total of 4300 forks have been made and there's currently four open pull requests,

163
13:32.130 --> 13:35.580
but 559 pull requests were closed.

164
13:35.580 --> 13:37.020
So let's have a look.

165
13:37.020 --> 13:43.290
So, for example, in this case, this guy updated the Readme to the current version.

166
13:43.290 --> 13:48.570
So that's obviously just editing a text file and that's pretty much within anybody's capabilities,

167
13:48.570 --> 13:49.050
right?

168
13:49.050 --> 13:55.680
And then it got merged by somebody who owned this repository and they gave them a bit of feedback.

169
13:55.680 --> 13:56.130
Right?

170
13:56.130 --> 14:02.940
But there's other things like, you know, code additions or code deletions or modifications that people

171
14:02.940 --> 14:03.690
have made.

172
14:03.690 --> 14:08.640
So this guy made some fixes and he's documented:

173
14:08.640 --> 14:09.480
what were the goals,

174
14:09.480 --> 14:13.230
what were the implementation details, what were the tests that he performed?

175
14:13.230 --> 14:18.360
And then the guy who owned the repository said, hey, just, you know, maybe one thing that you need

176
14:18.360 --> 14:19.320
to change.

177
14:19.320 --> 14:20.310
Have a look in here.

178
14:20.310 --> 14:25.410
And then once it was changed, then it was approved and merged with the master branch.

179
14:25.560 --> 14:31.380
Have a look around on GitHub and see what are some of the cool projects that you could maybe get involved

180
14:31.380 --> 14:32.880
in. To begin with,

181
14:33.000 --> 14:38.430
have a look at the libraries that you've been using and if you want, you can build on top of it, either

182
14:38.430 --> 14:40.770
for your own goals and purposes,

183
14:40.770 --> 14:45.930
but also, you know, if you're building on top of somebody else's open-source code, then it's a nice

184
14:45.930 --> 14:53.610
thing to contribute back to the open source world by forking and making a pull request to offer your

185
14:53.610 --> 14:56.760
improvements or bug fixes or new features.

186
14:56.790 --> 15:05.670
As I said, it's almost like a social network for programmers, and you can make a lot of great friends

187
15:05.670 --> 15:11.430
on here, and you can also get a lot of help on here in your development journey.

188
15:11.880 --> 15:17.040
So I hope you enjoyed all of that and I will see you on the next lesson.