So another thing we can do if we're working on a repository with collaborators is add in branch protection
rules.
So if we go into settings, assuming that you are somebody who has access to settings on the repository
under branches.
We have, first of all, the default branch.
You can configure this.
So if you want to make it something else, for example, if you have main and master and you realize
you only want Main to be the default, well, I shouldn't say only you can only have one default.
So if you want to switch that to Main, then you could do that here.
But we already have main hours.
Or if we needed to change it in some way, you can change that default branch.
But then down here it says branch protection rules define branch protection rules to disable force pushing,
prevent branches from being deleted and optionally requires status checks before merging new to branch
protection rules.
Learn more.
So we're going to add a rule.
We're going to protect our main branch.
The first thing it asks is for a branch name pattern.
Now, instead of just a branch name, it gives us the option of putting a pattern in here because on
large projects there may be thousands of branches that are pushed up or pull requests generated from,
and the organization or the project enforces rules where they need to be something like slash feature,
slash block or slash release.
If it's a big release of I can't spell release, but there are different patterns and you can define
different rules for those different types of branches instead of having to name each one.
But we're not going to do that.
We only have our main branch, so we'll just put Main in there and then I'm going to do this require
pull request reviews before merging.
This means that our commits need to be made to a non protected branch, basically not main and then
submitted via pull request and then at least one person, which is that we've only got two here, so
only one person needs to approve the PR before it can be merged.
So I just want to demonstrate how that would work.
There are other things, right?
Do we allow people to delete matching branches or not?
But we're just going to go with require pull request reviews.
So create.
Now we have this branch rule that applies to one branch main.
It is protected.
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
branch.
First of all, if I try, let's update even just the read me directly on main.
I'm going to start editing this.
So feature branch workflow.
How about Bok?
Bok?
I'm going to try and commit this and take a look.
It says you can't commit to Main because it's a protected branch.
Earlier I showed an example of this and we could just commit directly to Main, but now I can't.
So it wants me to make a new branch and start a pull request.
So I'm going to do it just in the browser instead of doing it locally.
It would be the same exact process though.
I make a feature branch, make my changes, push up the feature branch.
So this just makes me a feature branch and I use the default name it gave me.
Stephie Chicks Patch one.
All right, so now I can make my PR from CV Chicks Patch one to Main and I'm going to create that PR,
but I can't merge it.
Look, merging is blocked.
Earlier, when we had made peers, as Stevie, I showed you that I could just merge it in myself.
There is no real there's nothing preventing me from doing it.
Aside from being a, I guess, a trustworthy developer.
I could make a PR that did something bad and broke master or broke the main branch and just merge it
in.
But now because of the protection rule we set up, we need at least one approving reviewer.
So I'm going to go as code and be that approving reviewer hopefully.
So here is that PR.
It says it needs a review so I can add it if I want or I'm an administrator.
Right.
I'm the owner of this project, so I can just directly merge it, but I'm going to add a review.
So adding review is super simple.
If I'm good with it can click this, but I can also add a note, a comment about things and say like,
you know, always with the bok bok Stevie get a new catchphrase.
I'm joking around here, but you know, we can add things in like that.
We can then start a review.
So I can just add a single comment if I want.
Stevie will then be able to see that over here.
You can see it shows up for Stevie.
I reviewed it as always, blah, blah, blah blah blah.
He can respond back to me.
Bok, bok.
Bok.
Now I go back to my side.
I may need to refresh here.
There you see Steve's response.
So now a quick review changes.
I can finish the review and I can improve so I can approve merging the changes, or I can request that
he makes additional changes.
Or I can just leave a comment without actually approving it.
But I'm going to approve now.
So that was the review.
It's still not merged in.
So now at least one person has approved it, which is the rule we set up.
You can have it be more.
You can have two, three for however many people you need to approve it.
There's all different fancy permission things you can get into, especially if you have an organisation
set setup or an enterprise account.
Anyway, now I can merge that in here.
Right.
That wasn't showing up before, so I'm just going to merge it.
It's a very silly change to make and I'm going to confirm that merge and that will close the PR.
We can delete that branch and now the master branch that read me contains bok bok at the very bottom.
So silly little example, but I wanted to show that we can set up these protection rules and they're
very, very useful, especially if you have a bunch of people working on one project together and they're
making a lot of pull requests, and you want to be able to have some quality control or some feedback
process in place where people can't just directly change the main branch.
They instead are asked to make a pull request and then get feedback from at least one person.