1
00:00:07,590 --> 00:00:09,030
You know what is up.

2
00:00:09,040 --> 00:00:16,090
Everybody this is Jason whatever Klopstock com and in this video we are going to learn how to handle

3
00:00:16,210 --> 00:00:17,350
merge conflicts.

4
00:00:17,350 --> 00:00:25,420
All right now merge conflicts happen when there are two developers working in the same codebase and

5
00:00:25,450 --> 00:00:31,570
someone accidentally changes the same line of code that maybe somebody else was working on.

6
00:00:31,570 --> 00:00:32,160
All right.

7
00:00:32,230 --> 00:00:39,460
And then when those changes are committed up to get or get a hub it gets confused and it's like dude

8
00:00:39,960 --> 00:00:43,020
there's changes on both sides on the same line.

9
00:00:43,030 --> 00:00:46,960
I don't know what to do with it so we're going to go ahead and in this example we're going to create

10
00:00:47,020 --> 00:00:50,900
our own merge conflict and I'm going to walk you through how to handle it.

11
00:00:50,950 --> 00:00:56,630
So go ahead and let's create a new repository.

12
00:00:57,160 --> 00:00:58,540
All right and we're going to call this

13
00:01:01,540 --> 00:01:07,970
let's just call this merge conflicts suck because they do.

14
00:01:08,290 --> 00:01:13,430
I'm really good at creating these subconsciously by the way I have a real knack for it.

15
00:01:13,930 --> 00:01:21,190
So anyways we've got our repo name merge conflicts suck and then go ahead and create the repository.

16
00:01:21,190 --> 00:01:27,320
All right and then with your SSA chair go ahead and get this copy to your clipboard.

17
00:01:27,320 --> 00:01:27,730
All right.

18
00:01:27,730 --> 00:01:32,140
And then what I want you to do is open up your terminal.

19
00:01:32,430 --> 00:01:32,730
OK.

20
00:01:32,740 --> 00:01:35,410
I'm going to minimize this for now.

21
00:01:35,440 --> 00:01:39,710
Get this in the center of the screen and let's enlarge this.

22
00:01:39,730 --> 00:01:49,240
So how do you merge conflicts happen here so to simulate this what we're going to do is I'm going to

23
00:01:49,240 --> 00:01:57,280
create two folders and then clone this repository into each of those folders and what these folders

24
00:01:57,280 --> 00:02:03,550
are going to represent is one coteries computer and like coater B's computer.

25
00:02:03,550 --> 00:02:04,220
All right.

26
00:02:04,270 --> 00:02:05,320
So let's do this.

27
00:02:05,320 --> 00:02:16,660
So in my home directory here I'm just going to create a directory make der Butsy merge conflict.

28
00:02:16,840 --> 00:02:19,600
If I could spot write merge conflict.

29
00:02:19,620 --> 00:02:20,020
All right.

30
00:02:20,020 --> 00:02:22,570
So we created a directory there.

31
00:02:22,700 --> 00:02:28,030
Actually no we're not going to call this a merge conflict and to call it coater A because these are

32
00:02:28,030 --> 00:02:34,120
people right we're dealing with people and then we're going to make another directory and we're going

33
00:02:34,120 --> 00:02:35,120
to call this code a B.

34
00:02:35,140 --> 00:02:36,460
This is going to be my buddy.

35
00:02:36,460 --> 00:02:39,500
We're both going to start on this really cool project together.

36
00:02:39,760 --> 00:02:40,120
All right.

37
00:02:40,120 --> 00:02:41,710
So I've got these two folders.

38
00:02:41,730 --> 00:02:42,350
All right.

39
00:02:42,550 --> 00:02:51,370
So coater a will say that's me comes into here and let's see I have to change directory in here so CD

40
00:02:52,060 --> 00:02:52,970
coater a.

41
00:02:53,110 --> 00:02:57,570
So now I'm in the directory and we're going to clone the repo that we just created.

42
00:02:57,760 --> 00:03:04,900
So get clone and then paste the u r l that we copied from get.

43
00:03:05,110 --> 00:03:08,860
So now we're cloning our Ribault merge conflicts suck.

44
00:03:08,890 --> 00:03:11,310
Go ahead and throw in a password if you need to.

45
00:03:11,680 --> 00:03:12,450
And cool.

46
00:03:12,460 --> 00:03:14,130
It says that we've got this report now.

47
00:03:14,140 --> 00:03:18,090
Remember the repository that we've just created is empty.

48
00:03:18,160 --> 00:03:21,060
So why don't we go ahead and add a file to this.

49
00:03:21,300 --> 00:03:28,750
Now be mindful that we created a folder called coater a and we cloned the directory into this folder.

50
00:03:28,810 --> 00:03:38,510
So we actually if we list this out we have to now step into our folder repo that we just cloned.

51
00:03:38,880 --> 00:03:41,320
All right so in here there's nothing.

52
00:03:41,350 --> 00:03:44,010
So let's go ahead and create a file.

53
00:03:44,050 --> 00:03:46,430
So we're just going to call this mangy ass.

54
00:03:47,200 --> 00:03:47,900
Cool.

55
00:03:48,040 --> 00:03:50,170
So I'm going to use a command here.

56
00:03:50,170 --> 00:03:56,680
I'm going to open up the Adam text editor and I've just got kind of a little hot key to open this up.

57
00:03:56,680 --> 00:04:00,310
You can just follow along or open it up in your own text editor.

58
00:04:00,310 --> 00:04:05,260
I'm going to do Adam dash period to open up the directory that I'm in.

59
00:04:05,380 --> 00:04:08,500
So it's going to launch Adamy here for me.

60
00:04:08,980 --> 00:04:14,550
And what we're going to do is we're going to create just two simple lines of code.

61
00:04:14,650 --> 00:04:15,720
Create some variables.

62
00:04:15,910 --> 00:04:19,230
So Varnum will say is equal to 50.

63
00:04:19,990 --> 00:04:20,630
All right.

64
00:04:20,650 --> 00:04:27,060
And then let's do bar truth is going to be.

65
00:04:27,970 --> 00:04:29,350
Hello world.

66
00:04:29,410 --> 00:04:31,040
I guess we can cap that.

67
00:04:31,110 --> 00:04:31,560
All right.

68
00:04:31,570 --> 00:04:33,120
Hello world.

69
00:04:33,280 --> 00:04:34,000
Sweet.

70
00:04:34,160 --> 00:04:40,940
So me being coater a I just initiated this first project I created the repo.

71
00:04:40,990 --> 00:04:44,960
So what I'm going to do now is I'm going to go ahead and I'm going to push this up.

72
00:04:44,980 --> 00:04:47,980
So let me just put up some space here.

73
00:04:48,310 --> 00:04:54,340
So if we are to do a get status you can see that we have the untracked file that we just created.

74
00:04:54,340 --> 00:04:57,030
So I'm going to go ahead and add it to be tracked.

75
00:04:57,070 --> 00:05:01,220
Let's go ahead and committed and we'll add a message.

76
00:05:01,350 --> 00:05:06,770
First comments are right and then we'll go ahead and push this.

77
00:05:06,800 --> 00:05:13,250
Normally we always want to do a poll before we do the push but I'm the guy who created the report right.

78
00:05:13,250 --> 00:05:18,880
So I'm the first one pushing so I can simply just do a good push origin master.

79
00:05:19,370 --> 00:05:22,310
We're working on the master branch right now.

80
00:05:22,310 --> 00:05:22,750
All right.

81
00:05:22,750 --> 00:05:25,700
So enter my fancy password.

82
00:05:25,700 --> 00:05:30,370
All right so now that has been pushed over to bitbucket.

83
00:05:30,590 --> 00:05:34,660
I mean now that's been pushed over to get hub.

84
00:05:34,760 --> 00:05:39,950
So if we come into here and we refresh this you can see now that we've got our file in here.

85
00:05:40,180 --> 00:05:42,740
Ok going to minimize this.

86
00:05:42,740 --> 00:05:47,600
All right so now I'm going to you know message my buddy and say Yo dude I've got the repo created.

87
00:05:47,600 --> 00:05:50,420
Go ahead and clone it onto your own computer.

88
00:05:50,640 --> 00:05:52,700
It's like Do That sounds great.

89
00:05:52,700 --> 00:05:55,390
So I'm going to open up another tab here.

90
00:05:55,640 --> 00:06:03,430
I'm going to enter CD to go back to my home directory and remember we need to go into the coater B directory.

91
00:06:03,450 --> 00:06:06,600
OK this is going to be my buddy.

92
00:06:07,340 --> 00:06:10,600
And this represents a different computer OK.

93
00:06:10,630 --> 00:06:13,140
This is his computer at his house.

94
00:06:13,140 --> 00:06:13,590
All right.

95
00:06:13,730 --> 00:06:15,450
And there's nothing in here.

96
00:06:15,450 --> 00:06:18,690
So I'm going to go ahead and clone the repo again.

97
00:06:18,830 --> 00:06:24,990
And I've still got it copied to my clipboard so I'm going to paste it and hit enter.

98
00:06:25,000 --> 00:06:25,430
All right.

99
00:06:25,430 --> 00:06:29,110
Put in my fancy password and boom there it is.

100
00:06:29,240 --> 00:06:34,070
So if we list this out you can see we've got a repo on here.

101
00:06:34,070 --> 00:06:41,110
Let's go ahead and dive into the directory list down and we've got the javascript file on here.

102
00:06:41,120 --> 00:06:45,890
So again what I'm going to do is I'm on coater B's computer.

103
00:06:45,890 --> 00:06:49,150
I'm in a different directory and so I'm going to open up the same file here.

104
00:06:49,160 --> 00:06:55,930
So I'm going to use my text editor open this up and Adam.

105
00:06:56,070 --> 00:07:02,760
So we're going to have coater be over here on the right and a is going to be Orisha on the left and

106
00:07:02,760 --> 00:07:06,390
you can see the different file names here at the top.

107
00:07:06,690 --> 00:07:07,020
OK.

108
00:07:07,020 --> 00:07:10,110
So coater been my buddy.

109
00:07:10,110 --> 00:07:16,290
He's like oh man I see a bug in this code like we've got an error here.

110
00:07:16,620 --> 00:07:17,630
So we're going to do.

111
00:07:17,670 --> 00:07:18,090
Hello.

112
00:07:18,090 --> 00:07:20,220
Flat earth.

113
00:07:20,220 --> 00:07:23,250
Because we are not on the world right.

114
00:07:23,490 --> 00:07:25,060
Like this is a flat earth.

115
00:07:25,080 --> 00:07:28,250
So he's like Cool I've got these changes saved.

116
00:07:28,260 --> 00:07:31,020
I'm going to go ahead and push this up.

117
00:07:31,020 --> 00:07:36,930
So I'm in the coater be my buddy's computer here.

118
00:07:37,230 --> 00:07:43,170
And what we're going to do is we're going to do a guest status and we can see that we've bonafied the

119
00:07:43,170 --> 00:07:45,350
javascript file right we've changed it.

120
00:07:45,660 --> 00:07:46,050
All right.

121
00:07:46,080 --> 00:07:48,260
Let me go ahead and type in clear.

122
00:07:48,270 --> 00:07:50,070
Just to give us some more space.

123
00:07:50,160 --> 00:07:53,210
And so my buddy he fixed this bug.

124
00:07:53,370 --> 00:07:56,300
And so he's like all right I'm going to go ahead and add this.

125
00:07:56,430 --> 00:08:04,360
I'm going to do a commit here and I'm just going to try and fix the bug.

126
00:08:04,860 --> 00:08:13,680
And then we're going to go ahead and because we're good developers we're going to pull in Master into

127
00:08:13,680 --> 00:08:15,450
our branch here.

128
00:08:15,450 --> 00:08:18,910
So get the whole origin master.

129
00:08:19,020 --> 00:08:21,080
Now what do you think's going to happen here.

130
00:08:21,420 --> 00:08:30,570
So coater a I mean I officially initially created the code and my buddy cloned it and then he made a

131
00:08:30,570 --> 00:08:31,050
change to it.

132
00:08:31,050 --> 00:08:37,460
Now he's pushing it so if he does get Paul Orjan master let me show you what it's going to say here

133
00:08:38,330 --> 00:08:40,390
it says already up to date.

134
00:08:40,460 --> 00:08:41,740
Now why is that.

135
00:08:41,900 --> 00:08:50,330
Well I haven't made quarter or rehear hasn't made any new pushes since coater be my buddy over here

136
00:08:51,310 --> 00:08:57,050
is done with his stuff and is now pushing so good is going to say hey you've already cloned this.

137
00:08:57,050 --> 00:09:00,340
There hasn't been any changes from anybody else aside.

138
00:09:00,470 --> 00:09:03,160
So everything's Square it's all up to date.

139
00:09:03,260 --> 00:09:04,790
Go ahead and push.

140
00:09:04,940 --> 00:09:10,990
And so I'm going to get push origin and master.

141
00:09:11,050 --> 00:09:17,920
So now my buddy just pushes up his branch and everything pushes successfully.

142
00:09:18,310 --> 00:09:26,530
And then as I'm looking at my code coder a me I'm looking at this and I'm like oh dude shoot I've got

143
00:09:26,530 --> 00:09:34,330
an error in here and I haven't even talked to my other buddy to see if he's made changes or pushed and

144
00:09:34,330 --> 00:09:36,390
I haven't even checked myself.

145
00:09:36,400 --> 00:09:37,720
All right.

146
00:09:37,750 --> 00:09:46,060
If we opened up this and we refreshed it you can see that the last commit here was two minutes ago and

147
00:09:46,240 --> 00:09:48,490
the commit message has changed.

148
00:09:48,490 --> 00:09:51,500
So let's say that I'm diving into my project again.

149
00:09:51,700 --> 00:09:55,110
I haven't checked to see if any changes were made.

150
00:09:55,120 --> 00:10:03,100
I haven't talked to anybody and I was like OK I've got to fix this bug and we're going to say hello

151
00:10:03,580 --> 00:10:05,350
Flader Earth.

152
00:10:06,010 --> 00:10:07,800
So I fixed the bug.

153
00:10:07,810 --> 00:10:10,030
I'm feeling really good about this.

154
00:10:10,060 --> 00:10:15,390
So in my terminal I'm going to switch back over to the coder a directory.

155
00:10:15,430 --> 00:10:17,370
Let's clear this right.

156
00:10:17,380 --> 00:10:28,490
And if we do our guest status shows that we made we modify the change here so get it get commit and

157
00:10:28,490 --> 00:10:39,080
then fix that cray cray bug can edit my message and I am just an amazing developer so what am I going

158
00:10:39,080 --> 00:10:40,120
to do.

159
00:10:40,160 --> 00:10:46,540
I'm going to pull ma into my branch and let me tell you what's going on here.

160
00:10:46,730 --> 00:10:53,900
So let me I guess just enter on this and then type in my password and it says do it.

161
00:10:53,930 --> 00:11:00,980
There's there's a conflict here like What the heck's going on and what what good is screaming at us

162
00:11:00,980 --> 00:11:11,810
about is it says I have too much to commit here to pushes and line two in the same file has changed.

163
00:11:12,200 --> 00:11:14,990
And I don't know which ones which one is it.

164
00:11:15,020 --> 00:11:17,380
This one says right here.

165
00:11:17,380 --> 00:11:18,270
Is it supposed to be.

166
00:11:18,290 --> 00:11:19,770
Hello flat-Earth.

167
00:11:20,030 --> 00:11:23,300
Or is it supposed to be hello flat earth like the change you just made.

168
00:11:23,540 --> 00:11:31,190
Now in here you can see that Adam our text editor that kind of has some built in terminal tools I guess

169
00:11:31,190 --> 00:11:34,760
you could say and it's asking me which one is correct.

170
00:11:34,800 --> 00:11:37,380
Is it hello flat earth or is it.

171
00:11:37,550 --> 00:11:45,890
Hello flat earth like on your local you have one thing on your local machine and up in a remote repo.

172
00:11:45,990 --> 00:11:47,440
Or run get hub it's different.

173
00:11:47,440 --> 00:11:50,840
And I'm just confused and I don't know which one it is.

174
00:11:50,960 --> 00:11:56,200
Instead of solving this through our text editor I'm going to show you how to do this through the terminal.

175
00:11:56,690 --> 00:11:59,350
So what I'm going to do.

176
00:11:59,840 --> 00:12:01,190
I'm just going to finish reading this.

177
00:12:01,220 --> 00:12:07,740
It says that there is a conflict merge conflict in our main Jasc file and it says that it's failed and

178
00:12:07,740 --> 00:12:11,340
it has fixed these conflicts and then commit the result.

179
00:12:11,630 --> 00:12:15,420
All right so we're going to have to commit this again after we fix it.

180
00:12:15,860 --> 00:12:18,940
So what we want to do is type in the command.

181
00:12:18,950 --> 00:12:20,980
Let me just clean this up.

182
00:12:21,140 --> 00:12:25,060
We're going to type in a good merge tool.

183
00:12:25,250 --> 00:12:27,860
All one word hit enter.

184
00:12:28,280 --> 00:12:33,660
And you can see over in the text editor on my local it's created some backup files.

185
00:12:33,830 --> 00:12:35,250
That's ok don't worry about it.

186
00:12:35,300 --> 00:12:40,610
And then it says in our terminal just hit return to start the merge resolution tool.

187
00:12:40,790 --> 00:12:43,020
So I'm going to hit enter here.

188
00:12:43,430 --> 00:12:44,490
Awesome.

189
00:12:44,510 --> 00:12:52,640
So this is the get merge tool here and it shows right here you see how this says main local.

190
00:12:52,640 --> 00:12:56,040
This is what I changed it here on my local machine on my computer.

191
00:12:56,270 --> 00:13:01,280
And then it says but on the remote it's something different and it doesn't know which one to do.

192
00:13:01,670 --> 00:13:06,770
Well it gives us a couple of options how to handle this down here in the bottom right corner.

193
00:13:07,040 --> 00:13:10,330
You can see there's a dropdown that gives us some options.

194
00:13:10,490 --> 00:13:15,500
We can either choose the left side the right side we can say Oh both of them are right.

195
00:13:15,500 --> 00:13:18,040
Start with this side first or say you know what.

196
00:13:18,150 --> 00:13:19,450
Neither of these are right.

197
00:13:19,730 --> 00:13:27,080
So instead of choosing a side I'm going to say that I called my buddy and says bro you screwed everything

198
00:13:27,170 --> 00:13:30,510
up like we've got merge conflicts here what were you thinking.

199
00:13:30,680 --> 00:13:34,760
And we're going to talk it out and we're going to work things out we're going to still be friends we'll

200
00:13:34,770 --> 00:13:41,160
Seascale on the weekends and we're going to come to a conclusion that none of these answers are right.

201
00:13:41,180 --> 00:13:50,120
So what you can do is down here at the bottom we realize that we're both wrong and it's just Hellcats

202
00:13:50,150 --> 00:13:53,420
you know it wasn't about Earth being flat or round.

203
00:13:53,420 --> 00:13:55,640
It was really just about the cats.

204
00:13:55,640 --> 00:14:01,020
So what we can do now is go ahead and hit command s or control as to save it.

205
00:14:01,460 --> 00:14:08,510
And in the background I we minimize as you can see that it changed my local over to hello cats.

206
00:14:08,520 --> 00:14:08,840
All right.

207
00:14:08,840 --> 00:14:10,080
We fixed it.

208
00:14:10,100 --> 00:14:11,480
Pretty cool stuff.

209
00:14:11,480 --> 00:14:12,230
Now check this out.

210
00:14:12,230 --> 00:14:13,790
So we save this.

211
00:14:13,790 --> 00:14:16,710
You can go ahead and hit command cue or just close out of it.

212
00:14:17,150 --> 00:14:19,780
And then let's open up our terminal again.

213
00:14:20,210 --> 00:14:23,300
And so we fixed the resolution we resolved it.

214
00:14:23,300 --> 00:14:28,320
Now if I list out the items in here you'll see that I've got an extra file in here.

215
00:14:28,320 --> 00:14:30,630
This mangy stock a ridge.

216
00:14:30,680 --> 00:14:34,940
OK this is a backup that get made for us of this file.

217
00:14:34,940 --> 00:14:36,920
Just in case we needed a look back on it.

218
00:14:37,130 --> 00:14:38,300
Well we don't need it.

219
00:14:38,360 --> 00:14:45,270
So why don't we go ahead and remove it so remove maned are just on a ridge.

220
00:14:45,510 --> 00:14:45,970
OK.

221
00:14:46,100 --> 00:14:49,330
And you can see that it removed it from my local as well over here.

222
00:14:49,640 --> 00:14:50,060
All right.

223
00:14:50,060 --> 00:14:56,780
So remember it said that after we fix this Myrt conflict we have to commit again.

224
00:14:57,020 --> 00:15:03,060
So if we do a guest status it says changes to be committed we still have to commit this file here OK

225
00:15:03,150 --> 00:15:04,060
because we changed it.

226
00:15:04,060 --> 00:15:17,450
We updated it going to clear this give us some room so it can get dash in my buddy and I are still friends.

227
00:15:17,450 --> 00:15:17,950
All right.

228
00:15:18,140 --> 00:15:18,560
Cool.

229
00:15:18,590 --> 00:15:20,690
So I'm glad we work that out.

230
00:15:21,380 --> 00:15:29,220
All right so we've got that and then we can go ahead and push now and get push origin.

231
00:15:29,300 --> 00:15:32,670
M..

232
00:15:32,870 --> 00:15:36,750
All right let's put in our password and everything is good.

233
00:15:36,980 --> 00:15:38,540
It's all up to date now.

234
00:15:38,540 --> 00:15:42,100
Now check this out so we have fixed the merge conflict.

235
00:15:42,500 --> 00:15:45,410
I can call it my buddy and says dude we finally got this worked out.

236
00:15:45,410 --> 00:15:47,210
The master branch is up to date.

237
00:15:47,270 --> 00:15:55,560
Go ahead and pull that so he can simply just do a good whole Orjan master.

238
00:15:55,610 --> 00:15:56,600
This is coater B.

239
00:15:56,600 --> 00:15:57,490
This is my buddy.

240
00:15:57,710 --> 00:15:59,890
This is the other dude's computer.

241
00:16:00,200 --> 00:16:04,230
And watch this code over here watch what happens when he pulls from Master.

242
00:16:04,220 --> 00:16:08,560
Now we're going to do this on the password.

243
00:16:08,780 --> 00:16:10,200
And there you have it.

244
00:16:10,280 --> 00:16:15,670
He his his local branch now is fully up to date with master.

245
00:16:15,680 --> 00:16:18,500
So that is merge conflicts.

246
00:16:18,500 --> 00:16:24,920
In a nutshell and the best thing that you can do to prevent these merge conflicts is communicate talk

247
00:16:24,920 --> 00:16:31,610
to the other guys girls the developers make sure that everybody knows who's working on what features

248
00:16:31,700 --> 00:16:37,190
in what files and just keep that communication open and just make sure you're not in the same files

249
00:16:37,240 --> 00:16:41,290
touching the same lines of code that can get really really messy and complex sometimes.

250
00:16:41,390 --> 00:16:43,940
And that is a wrap for this section.

251
00:16:44,090 --> 00:16:44,870
Let's move on.

