Blog TIL Now Tags Projects About

Useful scripts for enabling branch protections via the GitHub API:

Terminal window
curl -L \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/branches/main/protection \
-d '{
"required_status_checks":null,
"enforce_admins":true,
"required_pull_request_reviews":{
"dismiss_stale_reviews":true,
"require_code_owner_reviews":false,
"required_approving_review_count":1
},
"restrictions":null,
"required_linear_history":false}'