1 00:00:00,120 --> 00:00:05,939 So another thing we can do if we're working on a repository with collaborators is add in branch protection 2 00:00:05,939 --> 00:00:06,750 rules. 3 00:00:07,020 --> 00:00:13,260 So if we go into settings, assuming that you are somebody who has access to settings on the repository 4 00:00:13,260 --> 00:00:14,520 under branches. 5 00:00:15,450 --> 00:00:17,520 We have, first of all, the default branch. 6 00:00:17,520 --> 00:00:18,690 You can configure this. 7 00:00:18,690 --> 00:00:23,820 So if you want to make it something else, for example, if you have main and master and you realize 8 00:00:23,820 --> 00:00:28,590 you only want Main to be the default, well, I shouldn't say only you can only have one default. 9 00:00:28,590 --> 00:00:31,890 So if you want to switch that to Main, then you could do that here. 10 00:00:31,890 --> 00:00:33,660 But we already have main hours. 11 00:00:34,110 --> 00:00:37,920 Or if we needed to change it in some way, you can change that default branch. 12 00:00:37,920 --> 00:00:43,950 But then down here it says branch protection rules define branch protection rules to disable force pushing, 13 00:00:43,950 --> 00:00:49,260 prevent branches from being deleted and optionally requires status checks before merging new to branch 14 00:00:49,260 --> 00:00:49,950 protection rules. 15 00:00:49,950 --> 00:00:50,730 Learn more. 16 00:00:50,730 --> 00:00:52,650 So we're going to add a rule. 17 00:00:52,650 --> 00:00:54,390 We're going to protect our main branch. 18 00:00:54,390 --> 00:00:57,330 The first thing it asks is for a branch name pattern. 19 00:00:57,330 --> 00:01:02,970 Now, instead of just a branch name, it gives us the option of putting a pattern in here because on 20 00:01:02,970 --> 00:01:09,690 large projects there may be thousands of branches that are pushed up or pull requests generated from, 21 00:01:09,690 --> 00:01:16,020 and the organization or the project enforces rules where they need to be something like slash feature, 22 00:01:16,500 --> 00:01:19,980 slash block or slash release. 23 00:01:19,980 --> 00:01:24,900 If it's a big release of I can't spell release, but there are different patterns and you can define 24 00:01:24,900 --> 00:01:29,490 different rules for those different types of branches instead of having to name each one. 25 00:01:29,700 --> 00:01:31,080 But we're not going to do that. 26 00:01:31,080 --> 00:01:36,090 We only have our main branch, so we'll just put Main in there and then I'm going to do this require 27 00:01:36,090 --> 00:01:39,120 pull request reviews before merging. 28 00:01:39,120 --> 00:01:44,610 This means that our commits need to be made to a non protected branch, basically not main and then 29 00:01:44,610 --> 00:01:50,550 submitted via pull request and then at least one person, which is that we've only got two here, so 30 00:01:50,550 --> 00:01:55,200 only one person needs to approve the PR before it can be merged. 31 00:01:55,470 --> 00:01:57,930 So I just want to demonstrate how that would work. 32 00:01:57,930 --> 00:01:59,130 There are other things, right? 33 00:01:59,130 --> 00:02:02,280 Do we allow people to delete matching branches or not? 34 00:02:02,610 --> 00:02:06,420 But we're just going to go with require pull request reviews. 35 00:02:06,420 --> 00:02:07,710 So create. 36 00:02:08,370 --> 00:02:11,490 Now we have this branch rule that applies to one branch main. 37 00:02:11,490 --> 00:02:12,750 It is protected. 38 00:02:12,990 --> 00:02:20,370 So if I try and act as Stevie, so I'm logged into Stevie here and I want to make a change to the main 39 00:02:20,370 --> 00:02:21,090 branch. 40 00:02:21,210 --> 00:02:26,880 First of all, if I try, let's update even just the read me directly on main. 41 00:02:28,890 --> 00:02:30,090 I'm going to start editing this. 42 00:02:30,090 --> 00:02:31,840 So feature branch workflow. 43 00:02:31,860 --> 00:02:33,990 How about Bok? 44 00:02:34,680 --> 00:02:35,340 Bok? 45 00:02:36,570 --> 00:02:39,300 I'm going to try and commit this and take a look. 46 00:02:39,300 --> 00:02:43,020 It says you can't commit to Main because it's a protected branch. 47 00:02:43,050 --> 00:02:48,570 Earlier I showed an example of this and we could just commit directly to Main, but now I can't. 48 00:02:48,570 --> 00:02:51,840 So it wants me to make a new branch and start a pull request. 49 00:02:51,840 --> 00:02:55,470 So I'm going to do it just in the browser instead of doing it locally. 50 00:02:55,470 --> 00:02:57,270 It would be the same exact process though. 51 00:02:57,270 --> 00:03:00,720 I make a feature branch, make my changes, push up the feature branch. 52 00:03:00,810 --> 00:03:05,100 So this just makes me a feature branch and I use the default name it gave me. 53 00:03:05,130 --> 00:03:06,660 Stephie Chicks Patch one. 54 00:03:07,080 --> 00:03:15,720 All right, so now I can make my PR from CV Chicks Patch one to Main and I'm going to create that PR, 55 00:03:17,850 --> 00:03:19,260 but I can't merge it. 56 00:03:19,650 --> 00:03:21,150 Look, merging is blocked. 57 00:03:21,420 --> 00:03:26,720 Earlier, when we had made peers, as Stevie, I showed you that I could just merge it in myself. 58 00:03:26,730 --> 00:03:29,700 There is no real there's nothing preventing me from doing it. 59 00:03:29,700 --> 00:03:33,360 Aside from being a, I guess, a trustworthy developer. 60 00:03:33,690 --> 00:03:38,730 I could make a PR that did something bad and broke master or broke the main branch and just merge it 61 00:03:38,730 --> 00:03:39,110 in. 62 00:03:39,120 --> 00:03:44,760 But now because of the protection rule we set up, we need at least one approving reviewer. 63 00:03:45,150 --> 00:03:50,610 So I'm going to go as code and be that approving reviewer hopefully. 64 00:03:50,610 --> 00:03:52,410 So here is that PR. 65 00:03:53,520 --> 00:03:58,590 It says it needs a review so I can add it if I want or I'm an administrator. 66 00:03:58,590 --> 00:03:58,830 Right. 67 00:03:58,860 --> 00:04:03,240 I'm the owner of this project, so I can just directly merge it, but I'm going to add a review. 68 00:04:03,630 --> 00:04:05,370 So adding review is super simple. 69 00:04:05,370 --> 00:04:12,420 If I'm good with it can click this, but I can also add a note, a comment about things and say like, 70 00:04:13,080 --> 00:04:22,830 you know, always with the bok bok Stevie get a new catchphrase. 71 00:04:23,880 --> 00:04:28,500 I'm joking around here, but you know, we can add things in like that. 72 00:04:28,500 --> 00:04:29,970 We can then start a review. 73 00:04:29,970 --> 00:04:32,970 So I can just add a single comment if I want. 74 00:04:33,210 --> 00:04:35,550 Stevie will then be able to see that over here. 75 00:04:35,880 --> 00:04:37,530 You can see it shows up for Stevie. 76 00:04:37,560 --> 00:04:40,620 I reviewed it as always, blah, blah, blah blah blah. 77 00:04:41,070 --> 00:04:42,660 He can respond back to me. 78 00:04:43,920 --> 00:04:44,820 Bok, bok. 79 00:04:44,820 --> 00:04:45,540 Bok. 80 00:04:49,130 --> 00:04:50,720 Now I go back to my side. 81 00:04:51,230 --> 00:04:52,760 I may need to refresh here. 82 00:04:53,840 --> 00:04:55,760 There you see Steve's response. 83 00:04:56,690 --> 00:04:58,820 So now a quick review changes. 84 00:04:58,940 --> 00:05:04,760 I can finish the review and I can improve so I can approve merging the changes, or I can request that 85 00:05:04,760 --> 00:05:06,380 he makes additional changes. 86 00:05:06,830 --> 00:05:09,650 Or I can just leave a comment without actually approving it. 87 00:05:09,920 --> 00:05:11,750 But I'm going to approve now. 88 00:05:14,420 --> 00:05:15,580 So that was the review. 89 00:05:15,590 --> 00:05:16,790 It's still not merged in. 90 00:05:17,030 --> 00:05:21,130 So now at least one person has approved it, which is the rule we set up. 91 00:05:21,140 --> 00:05:22,280 You can have it be more. 92 00:05:22,280 --> 00:05:25,730 You can have two, three for however many people you need to approve it. 93 00:05:26,210 --> 00:05:31,370 There's all different fancy permission things you can get into, especially if you have an organisation 94 00:05:31,370 --> 00:05:33,380 set setup or an enterprise account. 95 00:05:33,680 --> 00:05:36,820 Anyway, now I can merge that in here. 96 00:05:36,830 --> 00:05:37,220 Right. 97 00:05:37,220 --> 00:05:39,400 That wasn't showing up before, so I'm just going to merge it. 98 00:05:39,410 --> 00:05:46,250 It's a very silly change to make and I'm going to confirm that merge and that will close the PR. 99 00:05:46,340 --> 00:05:54,200 We can delete that branch and now the master branch that read me contains bok bok at the very bottom. 100 00:05:55,250 --> 00:06:00,350 So silly little example, but I wanted to show that we can set up these protection rules and they're 101 00:06:00,350 --> 00:06:05,990 very, very useful, especially if you have a bunch of people working on one project together and they're 102 00:06:05,990 --> 00:06:10,730 making a lot of pull requests, and you want to be able to have some quality control or some feedback 103 00:06:10,730 --> 00:06:15,770 process in place where people can't just directly change the main branch. 104 00:06:16,220 --> 00:06:21,470 They instead are asked to make a pull request and then get feedback from at least one person.