Skip to main content

Syncing to GitLab

You can sync your Modelbit git repo to a repo in your company's GitLab account. This is especially valuable for using your GitLab-based code review, CI/CD and Pull Request workflows on your Modelbit deployments.

This workflow requires you to have admin permissions within your GitLab account.

tip

Create a new, empty Git repository for use with Modelbit. The GitHub integration will not complete if the repo already has files.

Adding your GitLab repo URL to Modelbit

First, make a new GitLab repo inside your GitLab account.

Once created, from the main page of your GitLab repo, click the blue Clone button and copy out the URL. The URL will look like git@github.com:your-organization/repo-name.



Head back to Modelbit:

  1. In Settings, open the Git Settings page.
  2. Click the GitLab button, then click Next.
  3. Paste in the URL of your GitHub repo and click Next.

Before heading back to GitLab, copy the Deploy Key. This Deploy Key is Modelbit's public key for pushing and pulling your Git repo, just like a user's public key. It is not a secret.

Adding your Modelbit deploy key to GitLab

Open your repo in GitLab, then:

  1. On the left hand side, hover over Settings and click Repository.
  2. Click the "Expand" button next to Deploy Keys.
  3. Paste in the Modelbit deploy key in the Key field. Give the key a memorable title, like "Modelbit Integration".

Make sure to check "Grant write permissions to this key". Click Add Key.

tip

You must check the Grant write permissions to this key box in order for Modelbit to push changes to this repository.



Head back to Modelbit, click Next, and Modelbit will test the connection to GitLab. If the Deploy Key has been set with write access and no branch protection rules prevent Modelbit from syncing with the repo, you're all set.

Now Modelbit will sync to your GitLab repo, allowing you to use GitLab Merge Requests for merges, and all your GitLab-based tools for CI/CD, code review and more!

warning

Do not use git clone with this repository, use modelbit clone. The modelbit clone command will clone your repo and configure it to work with Modelbit.

Protected branches

You may enable protected branches to facilitate advanced git workflows with your team. However, you must allow the Modelbit integration to bypass the branch protection rules.

To allow Modelbit to continue to sync with your GitHub repository:

  1. In GitLab, go to Setting -> Repository
  2. Expand the Protected branches section
  3. Ensure that Modelbit's deploy key is selected under Allowed to push and merge
  4. Ensure that Allowed to force push is enabled

GitLab Webhooks

To ensure the quickest sync between GitLab and Modelbit, configure GitLab to notify Modelbit of changes using GitHub webhooks.

You'll find Modelbit's Webhook URL and Secret in the Git Settings page.

In GitLab, go to your repository's settings area and:

  1. Click Webhooks
  2. Paste Modelbit's Webhook URL into the URL field
  3. Paste Modelbit's Webhook Secret into the Secret token field
  4. Check the Push events box under Triggers
  5. Click Add webhook

The next time you push changes to GitLab, Modelbit will be notified and immediately sync the changes.