doc/user/project/repository/mirror/_index.md
{{< details >}}
{{< /details >}}
You can mirror a repository to and from external sources. You can select which repository serves as the source. Branches, tags, and commits are synced automatically.
Several mirroring methods exist:
Mirror a repository when:
The following is not supported:
Prerequisites:
ssh://, the host key must be detectable on the server,
or you must have a local copy of the key.In the top bar, select Search or go to and find your project.
Select Settings > Repository.
Expand Mirroring repositories.
Select Add new.
Enter a Git repository URL. The repository must be accessible over http://, https://, ssh://, or git://.
Select a Mirror direction. For more information, see pull mirroring and push mirroring.
If you entered an ssh:// URL, select either:
When mirroring the repository, GitLab confirms that at least one of the stored host keys matches before connecting. This check protects your mirror from malicious code injections, or your password from being stolen.
Select an Authentication method. For more information, see authentication methods for mirrors.
If you authenticate with SSH host keys, verify the host key to ensure it is correct.
To prevent force-pushing over diverged refs, select Keep divergent refs. For more information, see Keep divergent refs.
Optional. To limit the number of branches mirrored, select Mirror only protected branches or enter a regex in Mirror specific branches.
Select Mirror repository.
If you select SSH public key as your authentication method, GitLab generates a
public key for your GitLab repository. You must provide this key to the non-GitLab server.
For more information, see get your SSH public key.
To mirror a repository with SSH authentication:
In the top bar, select Search or go to and find your project.
Select Settings > Repository.
Expand Mirroring repositories.
Select Add new.
Enter a Git repository URL. Provide a URL in the format ssh://gitlab.com/gitlab-org/gitlab.git.
[!note] SSH URLs must use the format
ssh://host/path/to/repo.gitinstead of SCP-style URLs (git@host:path/to/repo.git). Replace the colon (:) with a slash (/) and add thessh://prefix.
Select a Mirror direction. For more information, see pull mirroring and push mirroring.
Select either Detect host keys or Input host keys manually.
In the Authentication method field, select SSH public key
In the Username field, add git.
Optional. Configure the Mirror branches settings.
Select Mirror repository.
Copy the SSH public key and provide it to your non-GitLab server.
You can choose to mirror only the protected branches in the mirroring project, either from or to your remote repository. For pull mirroring, non-protected branches in the mirroring project are not mirrored and can diverge.
To use this option, select Only mirror protected branches when you create a repository mirror.
{{< details >}}
{{< /details >}}
{{< history >}}
mirror_only_branches_match_regex removed.{{< /history >}}
To mirror only branches with names matching an RE2 regular expression, enter a regular expression into the Mirror specific branches field. Branches with names that do not match the regular expression are not mirrored.
When the mirror repository is updated, all new branches, tags, and commits are visible in the project's activity feed. A repository mirror at GitLab updates automatically. You can also manually trigger an update:
[!note] GitLab Silent Mode disables both push and pull updates.
While mirrors are scheduled to update automatically, you can force an immediate update unless:
Prerequisites:
When you create a mirror, you must configure the authentication method for it. GitLab supports these authentication methods:
For a project access token or group access token, use a non-blank value as a username and the token as the password.
SSH authentication is mutual:
For SSH authentication, you provide your credentials as a password or public key. The server that the other repository resides on provides its credentials as a host key. You must verify the fingerprint of this host key manually.
If you're mirroring over SSH (using an ssh:// URL), you can authenticate using:
When you mirror a repository and select the SSH public key as your authentication method, GitLab generates a public key for you. The non-GitLab server needs this key to establish trust with your GitLab repository. To copy your SSH public key:
authorized_keys file. Paste the entire public SSH key into the
file on its own line and save it.If you must change the key at any time, you can remove and re-add the mirror to generate a new key. Update the other repository with the new key to keep the mirror running.
[!note] The generated keys are stored in the GitLab database, not in the file system. Therefore, SSH public key authentication for mirrors cannot be used in a pre-receive hook.
When using a host key, always verify the fingerprints match what you expect. GitLab.com and other code hosting sites publish their fingerprints for you to check:
Other providers vary. You can securely gather key fingerprints with the following command if you:
$ cat /etc/ssh/ssh_host*pub | ssh-keygen -E md5 -l -f -
256 MD5:f4:28:9f:23:99:15:21:1b:bf:ed:1f:8e:a0:76:b2:9d [email protected] (ECDSA)
256 MD5:e6:eb:45:8a:3c:59:35:5f:e9:5b:80:12:be:7e:22:73 [email protected] (ED25519)
2048 MD5:3f:72:be:3d:62:03:5c:62:83:e8:6e:14:34:3a:85:1d [email protected] (RSA)
Older versions of SSH may require you to remove -E md5 from the command.