Skip to content
Cartly Developers

GitHub Theme Sync

Connect a GitHub repository to your theme for version-controlled development and automatic deploys on push.

Overview

GitHub Theme Sync lets you link any Cartly theme to a GitHub repository. Once connected, pushing to your configured branch automatically syncs the changed theme files into Cartly — no manual uploads required. Sync is one-way, from GitHub to Cartly.

  • GitHub OAuth connection (repo scope)
  • Automatic sync on push events via a webhook Cartly registers for you
  • Manual full re-sync via API
  • Files of a connected theme are read-only in Cartly (409, code github_readonly)
  • Full file history tracked in GitHub

Connect GitHub

Request the authorization URL from GET /admin/theme/github/connect and send the merchant to it. After the OAuth flow completes, Cartly stores the encrypted GitHub token for the shop. Importing a repository then registers the push webhook on it.

javascriptInitiate GitHub connection
// 1. Ask Cartly for the GitHub authorization URL (admin JWT required)
const res = await fetch("https://cartly.pro/admin/theme/github/connect", {
  headers: { Authorization: `Bearer ${adminToken}` },
});
const { redirect_url } = await res.json();

// 2. Send the merchant's browser to GitHub. After they authorize, GitHub
//    redirects to /api/github/callback and Cartly stores the encrypted token.
window.location.href = redirect_url;
javascriptImport a repository
// 3. Import a repository as a NEW unpublished theme
const res = await fetch("https://cartly.pro/admin/theme/github/import", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${adminToken}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ repo: "acme/my-store-theme", branch: "main" }),
});
const { id, name, sync_status } = await res.json(); // 201 Created

// 4. Poll the sync state
const status = await fetch(
  `https://cartly.pro/admin/theme/library/${id}/github-status`,
  { headers: { Authorization: `Bearer ${adminToken}` } }
).then((r) => r.json());
// { github_repo, github_branch, last_commit_sha, auto_deploy, sync_status, sync_error_log }

Sync a Theme

Importing creates a new unpublished theme and runs an initial full sync of the chosen branch (main if omitted); files missing from the repo are removed from the theme. Later pushes sync incrementally from the commits' added, modified and removed files. Put the theme folders (layouts/ or layout/, templates/, sections/, snippets/, blocks/, assets/, config/, locales/) at the repository root. layouts/theme.liquid is required. Liquid files over 256 KB and other files over 5 MB are skipped and reported in sync_error_log.

Auto-deploy Webhook

Cartly registers a webhook on the repository when you import or connect it, pointing at the global POST /api/webhooks/github endpoint. Every push to the configured branch starts an incremental sync workflow, and files are written through the theme service (fork-on-write). The payload is verified using the X-Hub-Signature-256 HMAC-SHA256 header; tag pushes and non-push events are ignored.

jsonWebhook push event
// GitHub push event, sent to the global endpoint
// POST https://cartly.pro/api/webhooks/github
// X-GitHub-Event: push
// X-Hub-Signature-256: sha256=<HMAC-SHA256(body, GITHUB_WEBHOOK_SECRET)>
{
  "ref": "refs/heads/main",
  "after": "abc123...",
  "repository": { "full_name": "acme/my-store-theme" },
  "commits": [{ "id": "abc123", "added": [], "modified": ["sections/header.liquid"], "removed": [] }]
}

// Cartly matches theme installs by repository full name + branch
// (no shop id in the URL) and responds: { "ok": true, "synced": 1 }

API Reference

Trigger a manual full re-sync via the Admin API:

javascriptManual sync via API
// Re-run a full sync from the connected branch (owner/admin only)
const response = await fetch(
  `https://cartly.pro/admin/theme/library/${themeId}/github-sync`,
  {
    method: "POST",
    headers: { Authorization: `Bearer ${adminToken}` },
  }
);

const { ok, sync_status } = await response.json(); // { ok: true, sync_status: "pending" }

// Link an EXISTING theme instead (API only, the admin UI imports a new theme):
// POST /admin/theme/library/:id/github-connect  { "repo": "acme/my-store-theme", "branch": "main" }
// Detach: POST /admin/theme/library/:id/github-disconnect