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