List branch rules for a project by using GraphQL
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
You can query for branch rules in a given project by using:
- GraphiQL.
cURL
.- The GitLab Development Kit (GDK).
Use GraphiQL
You can use GraphiQL to list the branch rules for a project.
Open GraphiQL:
- For GitLab.com, use:
https://gitlab.com/-/graphql-explorer
- For GitLab Self-Managed, use:
https://gitlab.example.com/-/graphql-explorer
- For GitLab.com, use:
Copy the following text and paste it in the left window. This query searches for a project by its full path, for example
gitlab-org/gitlab-docs
. It requests all configured branch rules for the project.query { project(fullPath: "gitlab-org/gitlab-docs") { branchRules { nodes { name isDefault isProtected matchingBranchesCount createdAt updatedAt branchProtection { allowForcePush codeOwnerApprovalRequired mergeAccessLevels { nodes { accessLevel accessLevelDescription user { name } group { name } } } pushAccessLevels { nodes { accessLevel accessLevelDescription user { name } group { name } } } unprotectAccessLevels { nodes { accessLevel accessLevelDescription user { name } group { name } } } } externalStatusChecks { nodes { id name externalUrl } } approvalRules { nodes { id name type approvalsRequired eligibleApprovers { nodes { name } } } } } } } }
Select Play.
If no branch rules are displayed, it might be because:
- No branch rules are configured.
- Your role doesn’t have permission to view branch rules. Administrators have access to all resources.
Use the GDK
Instead of requesting access, it may be easier for you to run the query in the GitLab Development Kit (GDK).
Sign in as the default admin,
root
, with the credentials from the GDK documentation.Ensure you have some branch rules configured for the
flightjs/Flight
project.In your GDK instance, open GraphiQL:
http://gdk.test:3000/-/graphql-explorer
.Copy the query and paste it in the left window.
Replace the full path with the following path:
query { project(fullPath: "flightjs/Flight") {
Select Play.
Related topics
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support