[GraphQL API] How to create a branch protection that allows force pushes?

I’m migrating from the REST API v3 to the GraphQL API v4.

Is there a GraphQL mutation similar to REST API’s “PUT /repos/:owner/:repo/branches/:branch/protection” to allow force pushes to the protected branch?

With the REST API, I can create a branch protection rule and set allow_force_pushes: true.

How can I do this with GraphQL? I don’t readily see how with CreateBranchProtectionRuleInput or UpdateBranchProtectionRuleInput.

For added context, in the GitHub UI this is the setting I’m trying to change via GraphQL API:



Per GitHub Support, the GraphQL API doesn’t expose this option.

Thanks for reaching out and asking us about this! The GraphQL API doesn’t currently expose that field today, though it could change in the future. We don’t have a timeline for if or when that would happen, though we encourage you to subscribe to our changelog: https://developer.github.com/v4/changelog/


As a workaround, we suggest continuing to use the REST API endpoint for updating that setting.

For me the problem is REST API does not support wildcards in brach name, so I cannot use it…

The workaround not really good since it depends on the particular branch. So to fetch “allow force push”/“allow deletions” options you need to query REST API N times where N is the number of the branches in the repository. Also REST API doesn’t return the rule pattern itself and you need to query it in the GraphQL API in additional queries. Completely not efficient and not useful.