Skip to content

Repository Settings and Branch Protection Rules ​

This page covers the basic settings handled in a repository's Settings, together with branch protection rules that guard shared branches against mistakes.

GitHub Repository Settings ​

You can configure rules for the whole repository from Settings in the project's top bar. (If you can't see Settings, you don't have permission, so ask for it.) Let's go over three important settings in the General menu of the left navigation.

Default Branch ​

This is the branch that is the default merge target when you create a PR. It's usually set to main, but you can change it to something like develop if needed. If you change it, PRs created from then on will request a merge into the new default branch.

Restricting PR Merge Types ​

You can force the use of only specific methods among the three covered earlier: Merge Commit / Squash / Rebase. This is useful when you want to unify the team's merge policy, especially when you want to keep a clean history.

Automatically Deleting Branches After Merge ​

Branches created for PRs are mostly one-off. If you turn on this option, the branch is deleted automatically the moment the PR is merged, saving you the trouble of cleaning up unused branches one by one.

Branch Protection Rules ​

Branch protection is a feature that stops one person's mistake from affecting all the other developers. It's usually applied to branches shared by many people, such as main/develop. You set it up in Settings → Branches → Add branch protection rule.

Which Branches to Protect: Name Patterns ​

Protection rules are applied based on a branch name pattern. You can write an exact name like main, or use a pattern like feature/* to protect every branch starting with feature/, such as feature/abc and feature/xyz, all at once. (It follows Unix-style glob pattern syntax.)

Commonly Used Settings ​

Require a pull request before merging Blocks direct pushes to the branch and forces everything to go through a PR. It prevents accidents like pushing to main by mistake without a review. Turning on this option also opens up sub-options.

  • Require approvals: a certain number of approvals is required before merging
  • Require review from Code Owners: a review from the code owners (CODEOWNERS) is required

Require linear history Forces merged commits to always keep a linear history. In other words, only rebase or squash is allowed for that branch, and the Merge Commit button can't be used.

Do not allow bypassing the above settings By default, the rules above only give a "warning," and administrators can ignore them and proceed. You have to turn on this option so that no one, without exception, can break the rules.

Summary ​

ConceptOne-line summary
Default BranchThe branch PRs merge into by default (usually main)
Branch Protection RulesEnforce requirements such as mandatory PRs and linear history on specific branches, based on name patterns

Source: Codyssey-B1/B2-2