Project remote mirrors API

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

Push mirrors defined on a project’s repository settings are called remote mirrors. You can query and modify the state of these mirrors with the remote mirror API.

For security reasons, the url attribute in the API response is always scrubbed of username and password information.

Pull mirrors use a different API endpoint to display and update them.

List a project’s remote mirrors

Get an array of remote mirrors and their statuses for a project.

GET /projects/:id/remote_mirrors

Supported attributes:

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

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

AttributeTypeDescription
auth_methodstringAuthentication method used for the mirror.
enabledbooleanIf true, the mirror is enabled.
host_keysarrayArray of SSH host key fingerprints for the remote mirror.
idintegerID of the remote mirror.
keep_divergent_refsbooleanIf true, divergent refs are kept when mirroring.
last_errorstringError message from the last mirror attempt. null if successful.
last_successful_update_atstringTimestamp of the last successful mirror update. ISO 8601 format.
last_update_atstringTimestamp of the last mirror attempt. ISO 8601 format.
last_update_started_atstringTimestamp when the last mirror attempt started. ISO 8601 format.
only_protected_branchesbooleanIf true, only protected branches are mirrored.
update_statusstringStatus of the mirror update. Possible values: none, scheduled, started, finished, failed.
urlstringMirror URL with credentials scrubbed for security.

Example request:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/42/remote_mirrors"

Example response:

[
  {
    "enabled": true,
    "id": 101486,
    "auth_method": "ssh_public_key",
    "last_error": null,
    "last_successful_update_at": "2020-01-06T17:32:02.823Z",
    "last_update_at": "2020-01-06T17:32:02.823Z",
    "last_update_started_at": "2020-01-06T17:31:55.864Z",
    "only_protected_branches": true,
    "keep_divergent_refs": true,
    "update_status": "finished",
    "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git",
    "host_keys": [
      {
        "fingerprint_sha256": "SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw"
      }
    ]
  }
]

Get a single project’s remote mirror

Get a single remote mirror and its status for a project.

GET /projects/:id/remote_mirrors/:mirror_id

Supported attributes:

AttributeTypeRequiredDescription
idinteger or stringYesID or URL-encoded path of the project.
mirror_idintegerYesID of the remote mirror.

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

AttributeTypeDescription
enabledbooleanIf true, the mirror is enabled.
idintegerID of the remote mirror.
host_keysarrayArray of SSH host key fingerprints for the remote mirror.
keep_divergent_refsbooleanIf true, divergent refs are kept when mirroring.
last_errorstringError message from the last mirror attempt. null if successful.
last_successful_update_atstringTimestamp of the last successful mirror update. ISO 8601 format.
last_update_atstringTimestamp of the last mirror attempt. ISO 8601 format.
last_update_started_atstringTimestamp when the last mirror attempt started. ISO 8601 format.
only_protected_branchesbooleanIf true, only protected branches are mirrored.
update_statusstringStatus of the mirror update. Possible values: none, scheduled, started, finished, failed.
urlstringMirror URL with credentials scrubbed for security.

Example request:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/42/remote_mirrors/101486"

Example response:

{
  "enabled": true,
  "id": 101486,
  "last_error": null,
  "last_successful_update_at": "2020-01-06T17:32:02.823Z",
  "last_update_at": "2020-01-06T17:32:02.823Z",
  "last_update_started_at": "2020-01-06T17:31:55.864Z",
  "only_protected_branches": true,
  "keep_divergent_refs": true,
  "update_status": "finished",
  "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git",
  "host_keys": [
    {
      "fingerprint_sha256": "SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw"
    }
  ]
}

Get a single project’s remote mirror public key

Get the public key of a remote mirror that uses SSH authentication.

GET /projects/:id/remote_mirrors/:mirror_id/public_key

Supported attributes:

AttributeTypeRequiredDescription
idinteger or stringYesID or URL-encoded path of the project.
mirror_idintegerYesID of the remote mirror.

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

AttributeTypeDescription
public_keystringPublic key of the remote mirror.

Example request:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/42/remote_mirrors/101486/public_key"

Example response:

{
  "public_key": "ssh-rsa AAAAB3NzaC1yc2EA..."
}

Create a pull mirror

Learn how to configure a pull mirror by using the project pull mirroring API.

Create a push mirror

Create a push mirror for a project. Push mirroring is disabled by default. To enable it, include the optional parameter enabled when you create the mirror.

POST /projects/:id/remote_mirrors

Supported attributes:

AttributeTypeRequiredDescription
idinteger or stringYesID or URL-encoded path of the project.
urlstringYesTarget URL to which the repository is mirrored.
auth_methodstringNoMirror authentication method. Accepted values: ssh_public_key, password.
enabledbooleanNoIf true, the mirror is enabled.
keep_divergent_refsbooleanNoIf true, divergent refs are kept when mirroring.
mirror_branch_regexstringNoRegular expression for branch names to mirror. Only branches with names matching the regex are mirrored. Requires only_protected_branches to be disabled. Premium and Ultimate only.
only_protected_branchesbooleanNoIf true, only protected branches are mirrored.

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

AttributeTypeDescription
auth_methodstringAuthentication method used for the mirror.
enabledbooleanIf true, the mirror is enabled.
host_keysarrayArray of SSH host key fingerprints for the remote mirror.
idintegerID of the remote mirror.
keep_divergent_refsbooleanIf true, divergent refs are kept when mirroring.
last_errorstringError message from the last mirror attempt. null if successful.
last_successful_update_atstringTimestamp of the last successful mirror update. ISO 8601 format.
last_update_atstringTimestamp of the last mirror attempt. ISO 8601 format.
last_update_started_atstringTimestamp when the last mirror attempt started. ISO 8601 format.
only_protected_branchesbooleanIf true, only protected branches are mirrored.
update_statusstringStatus of the mirror update. Possible values: none, scheduled, started, finished, failed.
urlstringMirror URL with credentials scrubbed for security.

Example request:

curl --request POST \
  --data "url=https://username:token@example.com/gitlab/example.git" \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/42/remote_mirrors"

Example response:

{
    "enabled": false,
    "id": 101486,
    "auth_method": "password",
    "last_error": null,
    "last_successful_update_at": null,
    "last_update_at": null,
    "last_update_started_at": null,
    "only_protected_branches": false,
    "keep_divergent_refs": false,
    "update_status": "none",
    "url": "https://*****:*****@example.com/gitlab/example.git",
    "host_keys": [
      {
        "fingerprint_sha256": "SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw"
      }
    ]
}

Update a remote mirror’s attributes

Update a remote mirror’s configuration. Toggle a remote mirror on or off, or change which types of branches are mirrored.

PUT /projects/:id/remote_mirrors/:mirror_id

Supported attributes:

AttributeTypeRequiredDescription
idinteger or stringYesID or URL-encoded path of the project.
mirror_idintegerYesID of the remote mirror.
auth_methodstringNoMirror authentication method. Accepted values: ssh_public_key, password.
enabledbooleanNoIf true, the mirror is enabled.
keep_divergent_refsbooleanNoIf true, divergent refs are kept when mirroring.
mirror_branch_regexstringNoRegular expression for branch names to mirror. Only branches with names matching the regex are mirrored. Does not work with only_protected_branches enabled. Premium and Ultimate only.
only_protected_branchesbooleanNoIf true, only protected branches are mirrored.

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

AttributeTypeDescription
auth_methodstringAuthentication method used for the mirror.
enabledbooleanIf true, the mirror is enabled.
host_keysarrayArray of SSH host key fingerprints for the remote mirror.
idintegerID of the remote mirror.
keep_divergent_refsbooleanIf true, divergent refs are kept when mirroring.
last_errorstringError message from the last mirror attempt. null if successful.
last_successful_update_atstringTimestamp of the last successful mirror update. ISO 8601 format.
last_update_atstringTimestamp of the last mirror attempt. ISO 8601 format.
last_update_started_atstringTimestamp when the last mirror attempt started. ISO 8601 format.
only_protected_branchesbooleanIf true, only protected branches are mirrored.
update_statusstringStatus of the mirror update. Possible values: none, scheduled, started, finished, failed.
urlstringMirror URL with credentials scrubbed for security.

Example request:

curl --request PUT \
  --data "enabled=false" \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/42/remote_mirrors/101486"

Example response:

{
    "enabled": false,
    "id": 101486,
    "auth_method": "password",
    "last_error": null,
    "last_successful_update_at": "2020-01-06T17:32:02.823Z",
    "last_update_at": "2020-01-06T17:32:02.823Z",
    "last_update_started_at": "2020-01-06T17:31:55.864Z",
    "only_protected_branches": true,
    "keep_divergent_refs": true,
    "update_status": "finished",
    "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git",
    "host_keys": [
      {
        "fingerprint_sha256": "SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw"
      }
    ]
}

Force push mirror update

Force an update to a push mirror.

POST /projects/:id/remote_mirrors/:mirror_id/sync

Supported attributes:

AttributeTypeRequiredDescription
idinteger or stringYesID or URL-encoded path of the project.
mirror_idintegerYesID of the remote mirror.

If successful, returns 204 No Content.

Example request:

curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/42/remote_mirrors/101486/sync"

Delete a remote mirror

Delete a remote mirror.

DELETE /projects/:id/remote_mirrors/:mirror_id

Supported attributes:

AttributeTypeRequiredDescription
idinteger or stringYesID or URL-encoded path of the project.
mirror_idintegerYesID of the remote mirror.

If successful, returns 204 No Content.

Example request:

curl --request DELETE \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/42/remote_mirrors/101486"