You can use below rest api to set branch permission fors for group.
POST https://dev.azure.com/{orgname}/{projectid}/_api/_security/ManagePermissions?__v=5
Here is a sample of request body.
{"updatePackage":
"{\"IsRemovingIdentity\":false,
\"TeamFoundationId\":\"{teamfoundationId}}\",
\"DescriptorIdentityType\":\"Microsoft.TeamFoundation.Identity\",
\"DescriptorIdentifier\":\"{DescriptorIdentifier}}\",
\"PermissionSetId\":\"2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87\",
\"PermissionSetToken\":\"repoV2/{projectId}}/{repoId}}/refs^heads^{branchname}}/\",
\"RefreshIdentities\":false,
\"Updates\":
[{\"PermissionId\":1,\"PermissionBit\":32768,\"NamespaceId\":\"2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87\",
\"Token\":\"repoV2/{projectId}/{repoId}/refs/heads/{branchId}/\"}],
\"TokenDisplayName\":null}"}
Note
\"PermissionId\":1
, means set the permission to Allow,
\"PermissionId\":2
, means set the permission to Deny,
\"PermissionId\":1
, means set the permission to Not Set.
\"PermissionBit\":32768
is the Bypass policies when completing pull requests permission.
\"PermissionBit\":128
is the Bypass policies when pushing permission.
\"PermissionBit\":4
is the Contribute policies when pushing permission.
\"PermissionBit\":2048
is the Edit polices permission.
\"PermissionBit\":8
is the Fource push permission.
\"PermissionBit\":8192
is the Manage permissions.
\"PermissionBit\":4096
is the remove other's lock permission.
Addition
There are too many parameters in the request body, you can get there parameters by offical documentations. Or I recommand you to get these parameters by using Network Tool to manual cathch them.