> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/on-premises/configuration/overleaf-toolkit/gitlab-synchronisation.md).

# GitLab Synchronisation

{% hint style="info" %}
This feature is developed by [ayaka-notes/ayakaleaf-pro](https://github.com/ayaka-notes/ayakaleaf-pro). It is introduced in v6.3.1 as an early preview and will be officially released in v6.4.0, so its configuration and behavior may still change. We need your feedback if you have any problem.
{% endhint %}

GitLab Synchronisation works like [GitHub Synchronisation](/on-premises/configuration/overleaf-toolkit/github-synchronisation.md): users link their GitLab account, export projects into new GitLab projects, import GitLab repositories, and sync changes in both directions. It works with GitLab.com and with self-managed GitLab 15.10 or later (Community and Enterprise Edition).

### Setup GitLab Synchronisation

{% hint style="warning" %}
You need to enable [git-bridge](/on-premises/configuration/overleaf-toolkit/git-integration.md) first before using GitLab Synchronisation.

{% code title="config/overleaf.rc" %}

```dotenv
GIT_BRIDGE_ENABLED=true
```

{% endcode %}
{% endhint %}

Create an OAuth application on your GitLab instance, under *User settings → Applications* (or *Admin area → Applications* for an instance-wide application):

* **Redirect URI**: `${OVERLEAF_SITE_URL}/user/gitlab-sync/oauth2/callback`
* **Confidential**: checked
* **Scopes**: `api`

Copy the **Application ID** and the **Secret**, then add the following settings to your overleaf env var files.

{% code title="config/variables.env" overflow="wrap" %}

```dotenv
# used to encrypt the user's GitLab access and refresh tokens.
# How to generate: `openssl rand -hex 32`
GITLAB_TOKEN_CIPHER_PASSWORD=0123456789ABCDEFG # changed to yours

# GitLab Sync Settings
GITLAB_SYNC_ENABLED=true
GITLAB_SYNC_CLIENT_ID=
GITLAB_SYNC_CLIENT_SECRET=

# Web address of your GitLab, defaults to https://gitlab.com
# GITLAB_SYNC_URL=https://gitlab.example.com

# OAuth callback is: ${OVERLEAF_SITE_URL}/user/gitlab-sync/oauth2/callback
# (Optional) GITLAB_SYNC_PROXY_URL=http://10.0.0.1:10808
```

{% endcode %}

{% hint style="warning" %}
Before configuring the GitLab OAuth redirect URI, make sure `OVERLEAF_SITE_URL` is set correctly.
{% endhint %}

GitLab access tokens expire after two hours. Overleaf refreshes them with the refresh token GitLab issues along with them, so users stay linked until they unlink or revoke the application in GitLab.

### Self-managed GitLab

Set `GITLAB_SYNC_URL` to the web address of your instance, the one you open projects with in the browser. The REST API is derived from it:

| Variable              | Default                     |
| --------------------- | --------------------------- |
| `GITLAB_SYNC_URL`     | `https://gitlab.com`        |
| `GITLAB_SYNC_API_URL` | `${GITLAB_SYNC_URL}/api/v4` |

Only set `GITLAB_SYNC_API_URL` when your instance serves the API somewhere else, for example behind an API gateway.

{% hint style="warning" %}

* Create the OAuth application on the instance you set in `GITLAB_SYNC_URL`, an application from `gitlab.com` does not work on a self-managed instance.
* `GITLAB_SYNC_URL` is the web address only. Do not add `/api/v4` or a group path.
  {% endhint %}

{% hint style="info" %}
If your instance uses a certificate from a private CA, mount the CA certificate into the container and point `NODE_EXTRA_CA_CERTS` at it, e.g. `NODE_EXTRA_CA_CERTS=/var/lib/overleaf/certs/gitlab-ca.pem`.
{% endhint %}

{% hint style="danger" %}
Linked accounts and projects belong to the instance they were linked with. Before switching `GITLAB_SYNC_URL` to another instance, ask users to unlink their GitLab account and projects.
{% endhint %}

If you are in a region with restricted network access, you may need to configure a proxy to access GitLab. Set the following environment variable: `GITLAB_SYNC_PROXY_URL=http://10.0.0.1:10808`. It must be a standard HTTP/HTTPS forward proxy, and must not use `127.0.0.1`.

### Who can link and sync

Like on Overleaf Cloud, only the project owner can link a project to a GitLab repository. Once it is linked, every collaborator with edit access can sync it.

| Action                                        | Who can do it                                      |
| --------------------------------------------- | -------------------------------------------------- |
| Export a project to a new GitLab repository   | The project owner                                  |
| Import a GitLab repository into a new project | Any user, who becomes the owner of the new project |
| Pull, push and merge a linked project         | The owner and collaborators with edit access       |
| Unlink a project from its repository          | The project owner                                  |

* Overleaf talks to GitLab with the GitLab account of the user who syncs, so every collaborator who syncs links their own GitLab account, and needs to be allowed to push to the default branch of the repository.
* View-only collaborators cannot use GitLab Synchronisation for the project.

### How syncing works with GitLab

* **Permissions**: users need to be allowed to push to the default branch of the linked project. When the default branch is protected and the user may not push to it, Overleaf asks them to contact the project owner, as with a repository they lost access to.
* **Merging**: when a project changed both in Overleaf and in GitLab, Overleaf commits its changes to a temporary branch named `overleaf-YYYY-MM-DD-HHMMSS` and merges it through a merge request, because GitLab has no API to merge branches without one. After the merge, Overleaf deletes the temporary branch and the merge request. Only administrators and project owners may delete merge requests in GitLab, so for other users the merged merge request stays in the project.
* **Merge rules**: Overleaf never bypasses the project's merge rules. When the merge request has a conflict, or needs an approval or a passing pipeline, it stays open and Overleaf asks the user to merge it in GitLab, then to continue syncing.
* **Pipelines**: commits from Overleaf start pipelines like any other commit. If your project runs pipelines for merge requests and requires them to pass, merges from Overleaf wait for them, as described above.

### Q\&A

<details>

<summary>Can I force push to the default branch?</summary>

**Answer:** Please keep force pushes to the default branch disabled. This is GitLab's default: the default branch of a new project is protected and no one can force push to it. Overleaf can take over a rewritten branch, but GitLab Synchronisation is designed for a default branch whose history only grows.

</details>

<details>

<summary>Can I rename the default branch of a linked project?</summary>

**Answer:** No. Overleaf keeps syncing with the branch the project was linked to, so syncs fail once that branch is renamed or removed. To sync with another branch, unlink the project, then import the repository into a new project, which uses the current default branch.

</details>

<details>

<summary>Does GitLab Synchronisation support Git LFS?</summary>

**Answer:** No. Overleaf projects do not support Git Large File Storage. Files tracked by Git LFS appear in Overleaf as LFS pointer files, not as their contents. Before GitLab 17.9, importing a repository brings in their contents, which the first sync replaces with the pointer files. Commit images and PDFs to the repository directly instead.

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ayakaleaf-pro.ayaka.space/on-premises/configuration/overleaf-toolkit/gitlab-synchronisation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
