Group push rules API

  • Tier: Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

Use push rules to control the content and format of Git commits your repository accepts. The push rules endpoints are only available to group Owners and administrators.

Get the push rules of a group

Gets the push rules of a group.

GET /groups/:id/push_rule

Supported attributes:

AttributeTypeRequiredDescription
idinteger or stringYesID of the group or URL-encoded path of the group.

If successful, returns 200 OK and the following response attributes:

AttributeTypeDescription
author_email_regexstringAllow only commit author emails that match this regular expression.
branch_name_regexstringAllow only branch names that match this regular expression.
commit_committer_checkbooleanIf true, allows commits from users only if the committer email is one of their own verified emails.
commit_committer_name_checkbooleanIf true, allows commits from users only if the commit author name is consistent with their GitLab account name.
commit_message_negative_regexstringReject commit messages matching this regular expression.
commit_message_regexstringAllow only commit messages that match this regular expression.
created_atstringDate and time when the push rule was created.
deny_delete_tagbooleanIf true, denies deleting a tag.
file_name_regexstringReject filenames matching this regular expression.
idintegerThe ID of the push rule.
max_file_sizeintegerMaximum file size (MB) allowed.
member_checkbooleanIf true, allows only GitLab users to author commits.
prevent_secretsbooleanIf true, rejects files that are likely to contain secrets.
reject_non_dco_commitsbooleanIf true, rejects a commit when it’s not DCO certified.
reject_unsigned_commitsbooleanIf true, rejects a commit when it’s not signed.

Example request:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/groups/2/push_rule"

Example response when push rules are configured with all settings disabled:

{
  "id": 1,
  "created_at": "2020-08-17T19:09:19.580Z",
  "commit_message_regex": "[a-zA-Z]",
  "commit_message_negative_regex": "[x+]",
  "branch_name_regex": "[a-z]",
  "author_email_regex": "^[A-Za-z0-9.]+@gitlab.com$",
  "file_name_regex": "(exe)$",
  "deny_delete_tag": false,
  "member_check": false,
  "prevent_secrets": false,
  "max_file_size": 0,
  "commit_committer_check": null,
  "commit_committer_name_check": false,
  "reject_unsigned_commits": null,
  "reject_non_dco_commits": null
}

If push rules were never configured for the group, returns 404 Not Found:

{
  "message": "404 Not Found"
}

When disabled, some boolean attributes return null instead of false. For example:

  • commit_committer_check
  • reject_unsigned_commits
  • reject_non_dco_commits

Add push rules to a group

Adds push rules to the group. Use only if you haven’t defined any push rules so far.

POST /groups/:id/push_rule

Supported attributes:

AttributeTypeRequiredDescription
idinteger or stringYesID or URL-encoded path of the group.
author_email_regexstringNoAllow only commit author emails that match the regular expression provided in this attribute, for example, @my-company.com$.
branch_name_regexstringNoAllow only branch names that match the regular expression provided in this attribute, for example, `(feature
commit_committer_checkbooleanNoIf true, allows commits from users only if the committer email is one of their own verified emails.
commit_committer_name_checkbooleanNoIf true, allows commits from users only if the commit author name is consistent with their GitLab account name.
commit_message_negative_regexstringNoReject commit messages matching the regular expression provided in this attribute, for example, ssh\:\/\/.
commit_message_regexstringNoIf true, allows only commit messages that match the regular expression provided in this attribute, for example, Fixed \d+\..*.
deny_delete_tagbooleanNoDeny deleting a tag.
file_name_regexstringNoReject filenames matching the regular expression provided in this attribute, for example, `(jar
max_file_sizeintegerNoMaximum file size (MB) allowed.
member_checkbooleanNoIf true, allows only GitLab users to author commits.
prevent_secretsbooleanNoIf true, rejects files that are likely to contain secrets.
reject_non_dco_commitsbooleanNoIf true, rejects a commit when it’s not DCO certified.
reject_unsigned_commitsbooleanNoIf true, rejects a commit when it’s not signed.

If successful, returns 201 Created and the following response attributes:

AttributeTypeDescription
author_email_regexstringAllow only commit author emails that match this regular expression.
branch_name_regexstringAllow only branch names that match this regular expression.
commit_committer_checkbooleanIf true, allows commits from users only if the committer email is one of their own verified emails.
commit_committer_name_checkbooleanIf true, allows commits from users only if the commit author name is consistent with their GitLab account name.
commit_message_negative_regexstringReject commit messages matching this regular expression.
commit_message_regexstringIf true, allows only commit messages that match this regular expression.
created_atstringDate and time when the push rule was created.
deny_delete_tagbooleanIf true, denies deleting a tag.
file_name_regexstringReject filenames matching this regular expression.
idintegerThe ID of the push rule.
max_file_sizeintegerMaximum file size (MB) allowed.
member_checkbooleanIf true, allows only GitLab users to author commits.
prevent_secretsbooleanIf true, rejects files that are likely to contain secrets.
reject_non_dco_commitsbooleanIf true, rejects a commit when it’s not DCO certified.
reject_unsigned_commitsbooleanIf true, rejects a commit when it’s not signed.

Example request:

curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/groups/19/push_rule?prevent_secrets=true"

Example response:

{
  "id": 1,
  "created_at": "2020-08-31T15:53:00.073Z",
  "commit_committer_check": false,
  "commit_committer_name_check": false,
  "reject_unsigned_commits": false,
  "reject_non_dco_commits": false,
  "commit_message_regex": "[a-zA-Z]",
  "commit_message_negative_regex": "[x+]",
  "branch_name_regex": null,
  "deny_delete_tag": false,
  "member_check": false,
  "prevent_secrets": true,
  "author_email_regex": "^[A-Za-z0-9.]+@gitlab.com$",
  "file_name_regex": null,
  "max_file_size": 100
}

Edit the push rules of a group

Edits the push rules for the group.

PUT /groups/:id/push_rule

Supported attributes:

AttributeTypeRequiredDescription
idinteger or stringYesID or URL-encoded path of the group.
author_email_regexstringNoAllow only commit author emails that match the regular expression provided in this attribute, for example, @my-company.com$.
branch_name_regexstringNoAllow only branch names that match the regular expression provided in this attribute, for example, `(feature
commit_committer_checkbooleanNoIf true, allows commits from users only if the committer email is one of their own verified emails.
commit_committer_name_checkbooleanNoIf true, allows commits from users only if the commit author name is consistent with their GitLab account name.
commit_message_negative_regexstringNoReject commit messages matching the regular expression provided in this attribute, for example, ssh\:\/\/.
commit_message_regexstringNoIf true, allows only commit messages that match the regular expression provided in this attribute, for example, Fixed \d+\..*.
deny_delete_tagbooleanNoIf true, denies deleting a tag.
file_name_regexstringNoReject filenames matching the regular expression provided in this attribute, for example, `(jar
max_file_sizeintegerNoMaximum file size (MB) allowed.
member_checkbooleanNoIf true, allows only GitLab users to author commits.
prevent_secretsbooleanNoIf true, rejects files that are likely to contain secrets.
reject_non_dco_commitsbooleanNoIf true, rejects a commit when it’s not DCO certified.
reject_unsigned_commitsbooleanNoIf true, rejects a commit when it’s not signed.

If successful, returns 200 OK and the following response attributes:

AttributeTypeDescription
author_email_regexstringAllow only commit author emails that match this regular expression.
branch_name_regexstringAllow only branch names that match this regular expression.
commit_committer_checkbooleanIf true, allows commits from users only if the committer email is one of their own verified emails.
commit_committer_name_checkbooleanIf true, allows commits from users only if the commit author name is consistent with their GitLab account name.
commit_message_negative_regexstringReject commit messages matching this regular expression.
commit_message_regexstringIf true, allows only commit messages that match this regular expression.
created_atstringDate and time when the push rule was created.
deny_delete_tagbooleanIf true, denies deleting a tag.
file_name_regexstringReject filenames matching this regular expression.
idintegerThe ID of the push rule.
max_file_sizeintegerMaximum file size (MB) allowed.
member_checkbooleanIf true, allows only GitLab users to author commits.
prevent_secretsbooleanIf true, rejects files that are likely to contain secrets.
reject_non_dco_commitsbooleanIf true, rejects a commit when it’s not DCO certified.
reject_unsigned_commitsbooleanIf true, rejects a commit when it’s not signed.

Example request:

curl --request PUT \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/groups/19/push_rule?member_check=true"

Example response:

{
  "id": 19,
  "created_at": "2020-08-31T15:53:00.073Z",
  "commit_committer_check": false,
  "commit_committer_name_check": false,
  "reject_unsigned_commits": false,
  "reject_non_dco_commits": false,
  "commit_message_regex": "[a-zA-Z]",
  "commit_message_negative_regex": "[x+]",
  "branch_name_regex": null,
  "deny_delete_tag": false,
  "member_check": true,
  "prevent_secrets": false,
  "author_email_regex": "^[A-Za-z0-9.]+@staging.gitlab.com$",
  "file_name_regex": null,
  "max_file_size": 100
}

Delete the push rules of a group

Deletes all the push rules of a group.

DELETE /groups/:id/push_rule

Supported attributes:

AttributeTypeRequiredDescription
idinteger or stringYesThe ID or URL-encoded path of the group.

If successful, returns 204 No Content with no response body.

Example request:

curl --request DELETE \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/groups/19/push_rule"