Protected branch
- Git course
- Advanced
- Lesson 49/56
- 4 min
Learn what a protected branch does.
What Is a Protected Branch?
On GitHub, a protected branch is a branch where specific rules prevent uncontrolled direct changes. It is commonly used to protect important branches such as main from accidental modifications or deletion. Branch protection is configured in repository settings.
main
├── Changes are reviewed
├── Rules are enforced
└── Safe merging is performedThese rules ensure that team members follow the same standards.
Rules Enforced by Branch Protection
Branch protection can restrict direct pushes, require reviews before merging, and require specific checks to succeed. It can also provide options that prevent accidental branch deletion or history changes. The selected rules depend on the project's needs.
main:
require_pull_request: true
prevent_deletion: trueThe purpose of these rules is not to stop development, but to make important changes controlled.
Practice Protect the Main Branch
Define a protection rule for the main branch. Set require_pull_request and prevent_deletion to true under rules. This ensures that changes go through pull requests and the branch cannot be deleted.
Starter code
# Dal koruma ayarlarını tamamla
# Pull request zorunluluğunu ekle
# Dal silinmesini engelleSample solution
main:
rules:
require_pull_request: true
prevent_deletion: trueExpected output
main dalı koruma kuralları etkinleştirildi.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which setting should be used to prevent direct changes to the main branch in a team?
- Creating a new tag
- Branch protection rules Correct answer
- Changing the repository description
- Viewing Git history
Explanation: Branch protection rules restrict which operations are allowed on important branches.
2 Direct Push Protection
main:
rules:
____: true
main:
rules:
require_pull_request: true
Explanation: Requiring pull requests ensures that changes reach the main branch through a review process.
3 Branch Protection Options
| Term | Meaning |
|---|---|
Dal koruması |
Restricts operations on a branch |
Pull request zorunluluğu |
Requires a PR before merging |
Silme koruması |
Prevents branch deletion |
Doğrudan push |
Can be restricted by protection |