Skip to main content

Syncing to GitHub

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

This workflow requires you to have admin permissions within your GitHub 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 GitHub repo URL to Modelbit

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

Once created, from the "Code" tab of your GitHub repo, click the green "Code" 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 GitHub button, then click Next.
  3. Paste in the URL of your GitHub repo and click Next.

Before heading back to GitHub, 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 GitHub

Open your repo in GitHub, then:

  1. Click the Settings tab of your repo.
  2. On the left hand side, click Deploy keys.
  3. On the upper right of this page, click Add deploy key.
  4. Paste the Modelbit deploy key. Give it a memorable name like Modelbit integration.

Make sure to check the Allow write access box and click save.

tip

You must check the Allow write access box in order for Modelbit to push changes to this repository.



Head back to Modelbit, click Next, and Modelbit will test the connection to GitHub. 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 GitHub repo, allowing you to use GitHub Pull Requests for merges, and all your GitHub-based tools for CI/CD, code review and more!

warning

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

Branch protection rules

You may enable branch protection rules 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, ensure that Deploy Keys are allowed to bypass the branch protection rules:

GitHub Webhooks

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

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

In GitHub, go to your repository's settings page and:

  1. Click Webhooks, then Add Webhook
  2. Paste Modelbit's Webhook URL into the Payload URL field
  3. Set Content Type to application/json
  4. Paste Modelbit's Webhook Secret into the Secret field
  5. Click Add Webhook
tip

Make sure to set the Content Type to application/json. The webhook won't work otherwise.

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