


Code review is a git best practice, so it’s worth checking this box. There are also users who don’t need to be restricted by approving reviews to merge changes.Ĭonversely, you can make the rule stricter by requiring approval before merging a pull request. A situation that comes to mind is when you need pull requests for continuous integration (CI) configuration or for tracking purposes. You don’t necessarily need to approve the pull requests before merging.

Then, they’ll need to submit a pull request before merging into the protected branch. Instead, users first have to commit to an unprotected branch. This rule ensures that collaborators cannot merge their pull requests or push directly to the branch. GitHub offers granular controls to match diverse workflows. But you can fine-tune the rules depending on the protection level you want.

The default branch protection is a good start. Finally, you can set these rules for a specific branch or for all branches in a repository. You can also temporarily disable the protection if you need to delete the branch or force-push changes. However, these rules do not apply to administrators unless specified. Similarly, users cannot delete the branch, whether intentionally or accidentally. This makes it impossible to overwrite the commit history. But we will go through them in detail to decide which ones you want to implement.īy default, no one can force push to the branch. Then, simply tick the box for the rules you want to enforce. GitHub will present you with the Rule settings under Protect matching branches. You’ll find this under the Branch name pattern. Next, type the branch name or pattern you’d like to protect. Next, choose your repository and click the Settings icon under the repository name.Ĭlick Add rule next to Branch protection rules. To create your rules, go to the repository’s main page. You can also create branch protection rules for branches that don’t exist yet. GitHub allows you to protect any branch you wish. Here’s how to set up your branch protection rules in GitHub: Step 1 – Enable Default Branch Protection GitHub branch protection rules help to avoid these scenarios. For example, a developer may introduce bugs to the code, delete a critical branch, or overwrite the commit history. Providing collaborators write access to your repository is an excellent way to collaborate on projects.
