Protected branches ensure that collaborators on your repository cannot make irrevocable changes to branches. Enabling protected branches also allows you to enable other optional checks and requirements, like required status checks and required reviews.
If you own a repository with multiple collaborators who create branches and open pull requests, you may need to enforce branch protections to keep your project and pull requests organized and safe.
Protected branches block some features of Git on a branch that a repository administrator chooses to protect. When you enable protected branches on a branch, collaborators:
- Can't force push to the branch
- Can't delete the branch
For more information, see "Configuring protected branches."
After enabling protected branches on a branch, you can choose to enable other optional checks and requirements, so that collaborators:
- Can't merge changes into the protected branch unless required status checks pass. For more information, see "About required status checks."
- Can't merge changes into the protected branch until required reviews are approved. For more information, see "Approving a pull request with required reviews."
- Can't edit the protected branch or upload files to it from the web
- Can't merge changes into the protected branch until changes to files that have a designated code owner have been approved by that owner. For more information, see "About codeowners."
If your repository belongs to an organization, you can restrict users or teams from pushing to a protected branch. For more information, see "About branch restrictions."