OPTIONAL: How to Make the "Your Main Branch Isn't Protected" Warning Go Away
Estimated time: ~10 minutes
GitHub may display this warning on your repository:
Your
mainbranch isn't protected. Protect this branch from force pushing or deletion, or require status checks before merging.
This explains what the warning means and how to address it.
GitHub Repository Branches
A Git branch is a version of your project's files and history.
Branches allow people to work on different changes independently.
For example, a team might create a separate branch
to develop a new feature without changing the main version of the project.
The default branch in a GitHub repository is typically named main.
In general, for individual projects,
the main branch is fine for all development.
In team situations, you may see additional branches.
Because main contains important project work,
we protect it from accidental deletion or unwanted changes to its history.
Protecting Main with Two Simple Rules
GitHub allows repository owners to establish rules that protect important branches.
- Restrict deletions: Prevents the
mainbranch from being accidentally deleted. - Block force pushes: Prevents someone from forcibly replacing the existing history of
main.
These help preserve work without altering the normal development process.
How to Protect Main
- Open your repository on GitHub.
- Select Settings near the top of the repository page.
- In the left sidebar, find Rules and select Rulesets.
- Select New ruleset, then New branch ruleset.
- Enter
Protect mainas the ruleset name. - Set Enforcement status to Active.
- Under Target branches, select Add target, then Include default branch.
- Under Branch rules, enable only these two options (which might be on by default):
- Restrict deletions
- Block force pushes
- Leave all other restrictions disabled.
- Select Create to save the ruleset.
GitHub may ask you to confirm your account credentials.
Verify
Return to your repository.
- Open Settings / Rules / Rulesets.
- Verify
Protect mainappears. - Verify its status is Active.
- Open the ruleset and confirm that it applies to the default branch and has the two protections enabled.
Return to the repository main page.
The warning about the unprotected main branch should no longer appear.
If the warning remains, confirm that the ruleset is active and applies to main.
Associated Skill
Help protect important project code from unintended alterations.
Reference
For more information, see the official GitHub documentation: