1 00:00:00,090 --> 00:00:05,880 So in the last video, the pull request that Stevie generated was able to be automatically merged in 2 00:00:05,880 --> 00:00:07,920 with a single button click, right? 3 00:00:08,280 --> 00:00:11,350 We didn't have to do any merging locally on our machine. 4 00:00:11,370 --> 00:00:14,580 It was all done in GitHub and then we just pulled down the changes. 5 00:00:14,580 --> 00:00:20,370 But that only happens sometimes where the merge can be done automatically, just like any merge in git. 6 00:00:20,400 --> 00:00:22,880 There's always a potential for conflicts. 7 00:00:22,890 --> 00:00:28,530 So in this video I want to show you how you can resolve conflicts when merging a pull request. 8 00:00:28,950 --> 00:00:29,350 Okay. 9 00:00:29,370 --> 00:00:33,990 So we need to first start by making a pull request that will generate a conflict. 10 00:00:33,990 --> 00:00:37,440 And to do that and to do things relatively speedily. 11 00:00:37,440 --> 00:00:44,080 Hopefully, I'm going to start by doing a tiny change as Stevie. 12 00:00:44,100 --> 00:00:46,320 So here we are as Stevie. 13 00:00:46,590 --> 00:00:48,480 I'm going to just I don't know. 14 00:00:48,480 --> 00:00:51,780 Well, let's change the title here of the entire Web page. 15 00:00:51,780 --> 00:00:54,780 So we'll imagine we're doing some big task. 16 00:00:54,780 --> 00:00:57,900 We're working on a feature branch, but really we're just going to change the heading. 17 00:00:57,900 --> 00:01:00,840 So let's make a feature branch as Stevie. 18 00:01:00,840 --> 00:01:01,830 We'll call this. 19 00:01:02,730 --> 00:01:04,019 We make this a bit larger. 20 00:01:04,260 --> 00:01:09,930 How about get let's see we're on main let's do get switch dash see because we're not going to work on 21 00:01:09,930 --> 00:01:13,110 main and then we'll call this new heading. 22 00:01:15,470 --> 00:01:22,910 So switch to a new branch, new heading, and now we can do some really basic work like change the heading 23 00:01:22,910 --> 00:01:23,390 here. 24 00:01:24,200 --> 00:01:25,350 Where is that? 25 00:01:25,370 --> 00:01:26,900 Instead of an H one. 26 00:01:26,930 --> 00:01:31,010 I'm going to give it a class of display one, which is just part of bootstrap. 27 00:01:31,490 --> 00:01:33,140 And let's see what it looks like. 28 00:01:33,500 --> 00:01:34,160 There it is. 29 00:01:34,160 --> 00:01:36,440 And then I'm going to change the text to B. 30 00:01:38,210 --> 00:01:39,110 I don't know. 31 00:01:39,970 --> 00:01:42,220 Hey yo world. 32 00:01:42,570 --> 00:01:44,710 Or how about actually, this is coming from Stevie? 33 00:01:44,860 --> 00:01:48,280 How about just back, back, back, back? 34 00:01:48,310 --> 00:01:49,110 Is that how you spell that? 35 00:01:49,120 --> 00:01:49,750 I don't know. 36 00:01:49,750 --> 00:01:51,580 Whatever noise my chickens make, it's like a. 37 00:01:53,110 --> 00:01:54,100 Most of the time. 38 00:01:54,460 --> 00:01:56,710 All right, so that's Stevie's change. 39 00:01:57,040 --> 00:01:59,590 So Stevie adds and commits this to the branch. 40 00:01:59,590 --> 00:02:04,450 So get add index, get commit change. 41 00:02:04,450 --> 00:02:05,870 Heading to black bark. 42 00:02:07,150 --> 00:02:14,920 All right, so now we can push that up or Stevie can push this branch get push origin new heading up 43 00:02:14,920 --> 00:02:15,610 to GitHub. 44 00:02:16,760 --> 00:02:22,410 Then simultaneously, I'm not going to go through the whole workflow of making a PR as Colt. 45 00:02:22,430 --> 00:02:29,720 I'm just going to do some changes on the index directly on the main branch, which normally we should 46 00:02:29,720 --> 00:02:30,380 be consistent. 47 00:02:30,380 --> 00:02:36,320 And if we're going to enforce pull requests, I guess I'm the the owner of this repo so I can do whatever 48 00:02:36,320 --> 00:02:36,880 I want. 49 00:02:36,890 --> 00:02:38,810 But normally you follow some rules. 50 00:02:38,990 --> 00:02:41,420 You're not going to have two sets of rules. 51 00:02:41,420 --> 00:02:45,440 You're going to ask everyone to use powers to merge changes in. 52 00:02:45,440 --> 00:02:52,940 But just to demo this faster and not lose your attention, I will directly edit the file on GitHub as 53 00:02:52,940 --> 00:02:53,480 Colt. 54 00:02:53,480 --> 00:02:53,660 Right. 55 00:02:53,720 --> 00:02:57,860 So I can just edit a file and make it commit on the main branch. 56 00:02:57,860 --> 00:03:02,060 So I'm going to edit this instead of saying hello world. 57 00:03:02,060 --> 00:03:03,260 Where's that heading? 58 00:03:03,680 --> 00:03:06,170 Right here it is instead of Hello World. 59 00:03:06,170 --> 00:03:18,140 I'll do hello there everyone and maybe a bunch of exclamation points then I'm going to save that. 60 00:03:18,140 --> 00:03:20,840 Well, not really save it, but I'm going to make a new commit. 61 00:03:20,840 --> 00:03:22,130 So update index. 62 00:03:22,130 --> 00:03:23,270 Sure, that's fine. 63 00:03:23,270 --> 00:03:25,310 Commit directly to the main branch. 64 00:03:25,310 --> 00:03:25,970 Here we go. 65 00:03:27,690 --> 00:03:33,060 So now the main branch has changed and Stevie has a branch that was pushed up. 66 00:03:33,210 --> 00:03:37,830 This is still kind of a trivial, silly way of of creating a conflict. 67 00:03:37,830 --> 00:03:42,570 But there should be a conflict now where if I try and make a pull request as Stevie. 68 00:03:43,870 --> 00:03:44,460 I'll take a look. 69 00:03:44,470 --> 00:03:45,880 Here's my new heading branch. 70 00:03:45,880 --> 00:03:47,350 Let's make a pull request. 71 00:03:48,940 --> 00:03:50,910 Oh can't automatically merge. 72 00:03:50,920 --> 00:03:55,660 Don't worry though, you can still create the pull request, so hopefully you see why we can't automatically 73 00:03:55,660 --> 00:03:56,110 merge. 74 00:03:56,110 --> 00:03:57,100 There's a conflict. 75 00:03:57,100 --> 00:04:00,310 Just like if we tried to merge these on our machine with git merge. 76 00:04:00,310 --> 00:04:02,230 It's the exact same mechanic. 77 00:04:02,230 --> 00:04:10,210 So if I want to make a pull request to change the heading to bok bok I am a chicken and I changed the 78 00:04:10,210 --> 00:04:13,330 heading to say bok buck. 79 00:04:13,450 --> 00:04:14,950 I hope you like it. 80 00:04:16,120 --> 00:04:16,930 So I have a message. 81 00:04:16,930 --> 00:04:18,519 I'll create that pull request. 82 00:04:20,000 --> 00:04:21,620 From New heading to Main. 83 00:04:22,400 --> 00:04:25,540 And we see that there are conflicts that can be resolved. 84 00:04:25,550 --> 00:04:32,030 So the way that our repo is set up, anybody who's a collaborator currently can resolve the conflicts 85 00:04:32,030 --> 00:04:33,650 right and merge a PR. 86 00:04:33,920 --> 00:04:38,350 Once that's resolved, I'm going to do it as colts, though, not as Stevie. 87 00:04:38,360 --> 00:04:42,980 That's a more typical workflow is somebody submits the PR and then it needs to be reviewed. 88 00:04:42,980 --> 00:04:48,830 So I'm going to go back to Colt's workspace and then we see there's a new PR. 89 00:04:49,340 --> 00:04:50,420 Here it is. 90 00:04:50,900 --> 00:04:56,780 And if I want to merge this in, unfortunately it's not as simple as clicking a button so I can do a 91 00:04:56,780 --> 00:04:57,530 couple of things. 92 00:04:57,620 --> 00:05:03,860 If I click the Resolve Conflicts button, it actually gives me an option to do this in the browser, 93 00:05:03,860 --> 00:05:05,930 which I haven't really done before. 94 00:05:06,590 --> 00:05:12,320 And this actually, for this example, is super easy to do it that way because it's just a single line 95 00:05:12,320 --> 00:05:13,970 that we're keeping or combining. 96 00:05:13,970 --> 00:05:18,620 But rather than doing it in the browser, I'm going to show you the good old fashioned way of doing 97 00:05:18,620 --> 00:05:21,230 it that you would do if you had a bunch of files. 98 00:05:21,560 --> 00:05:26,750 This is just one conflict in a single file, but in the real world you may run into conflicts across 99 00:05:26,750 --> 00:05:27,710 a bunch of files. 100 00:05:27,710 --> 00:05:33,020 Hopefully not too many, but still it might be easier to resolve them on your own machine so we can 101 00:05:33,020 --> 00:05:38,780 click this view command line instructions and it tells us exactly how to do this on the command line. 102 00:05:39,140 --> 00:05:43,250 So first we need to bring the changes in so we can fetch origin. 103 00:05:43,250 --> 00:05:45,470 So we'll do that on my machine as Colt. 104 00:05:45,500 --> 00:05:47,840 Get fetch origin. 105 00:05:49,260 --> 00:05:49,710 All right. 106 00:05:49,710 --> 00:05:54,720 So now we have this new branch reference, this remote tracking branch, to make this larger again. 107 00:05:55,720 --> 00:05:57,070 Oh, well, that didn't work. 108 00:05:57,340 --> 00:05:58,690 Try that one more time. 109 00:05:58,840 --> 00:05:59,560 Here we are. 110 00:05:59,890 --> 00:06:01,960 You can see Origin's new heading. 111 00:06:02,260 --> 00:06:03,310 So the instructions. 112 00:06:03,310 --> 00:06:10,270 Now, tell me to check out new heading there using the checkout command on the git or the github website. 113 00:06:10,270 --> 00:06:13,300 They don't use get switched yet, which is the newer way of doing it. 114 00:06:13,300 --> 00:06:14,800 So we could do this. 115 00:06:14,800 --> 00:06:20,710 We're saying make me a new branch called new heading and have it track origin slash new heading or the 116 00:06:20,710 --> 00:06:26,260 easier option is just to get switch new dash heading and it will do that for us as we've seen. 117 00:06:26,740 --> 00:06:33,790 So now that I've done that, I can see here I should have bok bok showing up in the heading and I do 118 00:06:33,790 --> 00:06:35,260 I have Steve's changes. 119 00:06:35,260 --> 00:06:40,270 I am currently checking out, I'm switching or I have switched to that new heading branch that Steve 120 00:06:40,270 --> 00:06:40,990 pushed up. 121 00:06:41,560 --> 00:06:44,320 So now I need to merge in the main branch. 122 00:06:44,320 --> 00:06:51,130 So this approach is switch to the new branch, the feature branch and merge main in to the feature branch, 123 00:06:51,130 --> 00:06:52,780 resolve the conflicts there. 124 00:06:53,050 --> 00:06:55,330 So just test things out and make sure it works. 125 00:06:55,330 --> 00:07:00,190 And then when we're ready, we're going to switch over to Main and merge new heading in. 126 00:07:01,330 --> 00:07:05,630 All right, so let's try that get merge main. 127 00:07:05,650 --> 00:07:06,870 This is the main branch. 128 00:07:06,880 --> 00:07:12,250 We know that there's likely going to be a conflict, although I think I am missing the latest changes 129 00:07:12,250 --> 00:07:13,060 from Main. 130 00:07:13,540 --> 00:07:16,420 Yeah, it's up to date because I didn't poll down. 131 00:07:16,420 --> 00:07:17,950 So let's switch to Main. 132 00:07:18,310 --> 00:07:19,190 I'll show you what I mean. 133 00:07:19,210 --> 00:07:20,440 Get Switch Main. 134 00:07:20,440 --> 00:07:24,870 Remember that I updated on Main on GitHub. 135 00:07:24,880 --> 00:07:29,770 I changed the heading and it actually tells me that your main branch is behind origin slash main. 136 00:07:29,770 --> 00:07:32,080 So we'll do a git pull origin main. 137 00:07:33,110 --> 00:07:35,210 Now we have the latest changes on Main. 138 00:07:35,240 --> 00:07:37,610 Now I can go back to new heading. 139 00:07:40,190 --> 00:07:41,990 And then I can merge main. 140 00:07:41,990 --> 00:07:44,390 So get merge the new main branch that we have. 141 00:07:44,420 --> 00:07:49,270 It's not new, but the latest version, the latest work merge that into this new heading branch. 142 00:07:49,280 --> 00:07:50,730 Now we have the conflict. 143 00:07:50,750 --> 00:07:53,060 So now I can resolve the conflict here. 144 00:07:53,210 --> 00:07:55,760 So maybe I want both. 145 00:07:55,790 --> 00:08:00,080 Maybe I want to h one class equals display one from Stevie. 146 00:08:00,500 --> 00:08:04,460 And then I want, I don't know, all these exclamation points. 147 00:08:04,550 --> 00:08:05,270 How about Bok? 148 00:08:05,270 --> 00:08:07,670 Bok, everyone like that. 149 00:08:09,530 --> 00:08:11,360 So let's see what that looks like. 150 00:08:12,440 --> 00:08:13,430 Let's refresh. 151 00:08:13,490 --> 00:08:14,850 Okay, great. 152 00:08:14,870 --> 00:08:17,060 So now we need to add and commit the changes. 153 00:08:17,060 --> 00:08:25,280 So get add index and we'll just do a useless commit message like resolve conflicts. 154 00:08:27,260 --> 00:08:31,610 So now we've merged the changes in, but we're just on the new heading branch. 155 00:08:31,670 --> 00:08:32,590 So we've made it. 156 00:08:32,600 --> 00:08:38,390 We know for sure that the current version of Master or Main works, when we merged it in with the changes 157 00:08:38,390 --> 00:08:40,539 on new heading, we resolve the conflicts. 158 00:08:40,549 --> 00:08:43,100 Now we can switch back to Main. 159 00:08:44,080 --> 00:08:49,480 And then we can merge in that new heading branch that we already resolved the conflicts on, which is 160 00:08:49,480 --> 00:08:52,390 exactly what they ask us to do or tell us to do on GitHub. 161 00:08:52,600 --> 00:08:58,510 So go back to Main and then merge in new heading, which already has the conflicts resolved. 162 00:08:58,510 --> 00:09:00,190 So we shouldn't get new conflicts. 163 00:09:00,220 --> 00:09:07,510 Now this dash dash no f f, that's an indicator that we're telling git merge to not fast forward if 164 00:09:07,510 --> 00:09:13,300 it detects that it can because when we do a fast forward instead of making a merge commit as we've seen, 165 00:09:13,480 --> 00:09:16,960 it will just move the branch pointer to some new commit. 166 00:09:16,960 --> 00:09:17,260 Right? 167 00:09:17,260 --> 00:09:21,970 It just moves forward and sometimes we want to prevent that from happening, especially when we want 168 00:09:21,970 --> 00:09:25,270 to preserve or maintain our specific branch. 169 00:09:25,270 --> 00:09:28,000 We want to make it clear that there was a branch merged in here. 170 00:09:28,000 --> 00:09:32,890 Just to have that history, you don't have to do this part, but it's just what GitHub recommends. 171 00:09:32,890 --> 00:09:35,080 So we could just copy the entire line. 172 00:09:35,530 --> 00:09:38,880 We're merging new heading into Main OC. 173 00:09:39,010 --> 00:09:44,320 So see, I'm now going to put a commit here instead of just a fast forward, I'm putting a merge commit 174 00:09:44,320 --> 00:09:47,500 in because I said no, fast forward. 175 00:09:47,710 --> 00:09:52,120 All right, and now we just push it up to master get push origin main. 176 00:09:52,120 --> 00:09:55,480 I said master again we're using main get push origin main. 177 00:09:59,050 --> 00:09:59,860 Oh, right. 178 00:09:59,860 --> 00:10:04,870 So now if I refresh this page, it automatically just I didn't I didn't refresh but it automatically 179 00:10:04,870 --> 00:10:10,390 detects successfully merge this PR and it's closed now and you can delete that new heading branch if 180 00:10:10,390 --> 00:10:10,860 you want. 181 00:10:10,870 --> 00:10:11,290 Sure. 182 00:10:11,290 --> 00:10:12,280 Let's delete it. 183 00:10:13,610 --> 00:10:15,320 We can also restore it if needed. 184 00:10:15,470 --> 00:10:22,580 And now we merged a PR in that had a conflict and the same process would apply if there was one conflict 185 00:10:22,580 --> 00:10:24,640 or tons and tons of conflicts. 186 00:10:24,650 --> 00:10:28,580 We make a request and then resolve the conflicts following the instructions. 187 00:10:28,580 --> 00:10:35,780 Basically pull that code down or fetch it, check it out or switch to the new feature branch merge master 188 00:10:35,780 --> 00:10:42,860 or main in resolve conflicts add and commit then switch back to master or main merge in the now conflict 189 00:10:42,860 --> 00:10:45,440 less branch and then push that up. 190 00:10:46,150 --> 00:10:52,250 Okay, so now the last thing to do is as STB, go and get the latest version right of the main branch. 191 00:10:52,250 --> 00:10:55,430 We don't have that as Stevie, so we just need to pull down. 192 00:10:55,430 --> 00:10:56,750 We'll switch to Main. 193 00:10:57,020 --> 00:11:04,550 We can remove that branch now new heading so get branch dash dx new heading. 194 00:11:05,740 --> 00:11:12,280 And now get pull origin man we'll get the latest changes from man and there's not a whole lot that we 195 00:11:12,280 --> 00:11:19,180 got but if we type get log we see OC we got the resolving of the conflict merge that branch in my work 196 00:11:19,180 --> 00:11:25,900 was merged in so now our latest version of the main branch says buck back everyone and we can take a 197 00:11:25,900 --> 00:11:29,130 look at it right here and there we are. 198 00:11:29,200 --> 00:11:32,890 So we successfully merged a PR in that had a conflict OC.