gh-repo-config: A GitHub CLI extension to manage repository settings | GitHub
API v3 doc to understand the fields in .github/config/branch-protection/
: https://docs.github.com/en/rest/branches/branch-protection#update-branch-protection--parameters
Example script using it to temporarily disable branch protection rules for a single git push
:
#!/bin/bash
set -o errexit
# Prerequisite: gh repo-config init must be called to initialized JSON config files
config_dir=.github/config/branch-protection
# Backup current configuration:
cp $config_dir/main.json .
# Disable branch protection rules:
yq -iP -o json .required_pull_request_reviews=null $config_dir/main.json
yq -iP -o json .required_status_checks.checks=[] $config_dir/main.json
gh repo-config apply
# Push commit(s):
git push
# Restore initial configuration
mv main.json $config_dir/
gh repo-config apply
⚠️ Currently gh repo-config init
does NOT reflect your current repo settings when initializing files in .github/config/branch-protection/
, cf. issue 159
⚠️ Calling gh repo-config apply
will NOT preserve your current repo settings
— Permalink