Git & GitHub Interview Question #76
What is a protected branch on GitHub?
GitHub Collaboration, Repository Rules, Issues, Releases & Actions CI/CD Mid-Level Intermediate
Quick Interview Answer
A protected branch is a branch governed by repository rules that restrict how changes can be made. Protection can require pull requests, reviews, status checks, signed commits, linear history, or other conditions before changes are accepted.
Detailed Explanation
A protected branch is a branch governed by repository rules that restrict how changes can be made. Protection can require pull requests, reviews, status checks, signed commits, linear history, or other conditions before changes are accepted.
Protected branches are commonly used for important branches such as main or release branches. The purpose is to reduce accidental or unauthorized changes and enforce the team's integration process.
Code Example
# Protection is configured on GitHub.
# Locally, developers still work normally:
git switch -c feature/payment-fix
git add .
git commit -m "Fix payment validation"
git push -u origin feature/payment-fix