github: branch protection
making sure PRs to master get code reviewed, for example
In professional software development settings, it is a common practice to protect the master branch.
That is, there may be some policy rules about merging changes into master:
- The code should be on a feature branch, and it should go into master via a pull request
- The code should be code reviewed
- If there are CI/CD scripts set up (e.g. GitHub actions), those should be passing, not failing
- The branch should be up-to-date with the changes in Master (not behind master)
- The merge should be done by someone with admin authority.
GitHub allows you to enforce some or all of these rules with branch protection.
Branch protection is configured in
- the
Settings
menu of the repo, - under
Branches
- then select
Branch Protection Rules
Note that an empty repo has no commits, and therefore no branches. So you must have at least one commit (e.g. a README.md file) before you can define branch protection rules.
Related topics:
- git: basic workflow—The basics: git add..., git commit..., git push ...
- git: cloning your first repo—A guide for those new to git
- git: commit messages—How to write clear and helpful commit messages
- git: feature branch workflow—One branch per feature/issue/story
- git: git/github troubleshooting—Various problems and their solution
- git: .gitignore files—What they are for and what to put in them
- git: merge conflicts—Not nearly as scary as you may have been told
- git: overview—An introduction. git vs. github.com vs. github.ucsb.edu, repos, etc.
- git: throwaway untracked files—how to clean up untracked files easily
- github: adding collaborators—giving individual users access to a private repo
- github: api—Java Api for Github
- github: branch protection—making sure PRs to master get code reviewed, for example
- github: issues—working with issues in github
- github: keyboard shortcuts—making the github web UI easier to use
- github: pro tips—A few extras to help you work with GitHub more effectively
- github: using ssh keys—generating public/private key pair, uploading public key to github
- github: ucsb-cs-github-linker—Using the local tool to join a course organization
- github: verified badge on commits—adding extra security to your commit messages