- Mirror a repository from GitHub
- Push to Code Storage and let Code Storage forward those writes to GitHub
- Continue to use Code Storage APIs, JWT-backed remotes, ephemeral branches, and webhooks on the mirrored repository
Sync modes
Code Storage currently supports three Git Sync modes:
This page covers the two GitHub modes. For every other host, see
Generic Sync.
GitHub App sync
The SDK has a direct setup flow for GitHub App sync. Create the repository with a GitHub base. CallpullUpstream() when you must force a refresh.
- Code Storage links the repository to GitHub when you create it with
baseRepo pullUpstream()gets the latest changes from GitHub- All SDK features work with the synced content, such as diffs, commits, and file access
- Code Storage sets the provider to
"github"whenbaseRepocontainsownerandname
409 Conflict:
repo.sync.succeeded webhook.
Git LFS on GitHub App sync
GitHub App sync repositories support Git LFS over the same Code Storage remote:- Downloads: Code Storage serves an object that it already stores. If the object is absent, the LFS client gets it from GitHub. Code Storage copies the object in the background for the next request.
- Uploads: The client sends object bytes directly to GitHub. Code Storage does not store the upload.
Public GitHub mode
If the upstream repository is public, you can skip GitHub App auth and create a synced repository in public mode.- Code Storage does not subscribe to GitHub webhooks
- Code Storage does not keep a continuous, two-way sync with GitHub
- Code Storage does not automatically copy changes from GitHub
- Code Storage does not automatically send changes to GitHub
- The GitHub repository must remain public. If it becomes private, use authenticated mode before you sync it again
Public mode vs GitHub App sync
Set up a GitHub App
Set up a GitHub App before you enable GitHub App sync.1
Create the app
Open Settings -> Developer settings -> GitHub Apps. Create a new GitHub App.
2
Set permissions
Repository permissions:Webhook events:Or use your own handler.
- Metadata: Read (required)
- Contents: Read for one-way sync from GitHub, or Read and write for bidirectional sync
- Workflows: Read and write (only if pushes will change files under
.github/workflows/)
Code Storage requests no fixed permission set when it creates an installation token. The
connection uses the permissions that the installation grants. If a permission is absent, the
related push fails. The setup can still succeed.
- Push
- Create
- Pull Request (optional, if you want PR sync)
3
Record credentials
Save these values for the Code Storage configuration:
- GitHub App ID
- Private Key
- Webhook Secret
Automatic sync with webhooks
GitHub sends webhook events when the repository changes. Handle the events in your service, or let Code Storage handle them.Option A: handle webhooks yourself
To use your own webhook handler, set the callback URL to its endpoint. Process each GitHub event. Call Code Storage as necessary.repo.pullUpstream() from your handler to start a GitHub sync.
GitHub sends the x-hub-signature-256 header. GitHub uses your GitHub App webhook secret to sign
the payload. Use the GitHub documentation to check this signature.
Code Storage also sends events for pushes and each sync stage. See Webhooks for
the event list, payloads, headers, and HMAC check.
Option B: let Code Storage handle webhooks
If you do not want to run your own webhook handler:- In your GitHub App settings, set the webhook URL to
https://[your-organization].code.storage/webhooks/github - Generate a webhook secret and save it.
- In the Code Storage dashboard, open the Integrations tab.
- Enter your webhook secret and save it.
How Git Sync behaves
After you configure Git Sync, these rules apply:git clone,git fetch, andgit pullread from Code Storagerepo.pullUpstream()andPOST /api/repos/{repo_name}/pull-upstreamstart an asynchronous refresh from GitHub- Code Storage forwards each
git pushto GitHub - A successful push starts a background sync to keep the Code Storage nodes current
+ephemeral remote stay in Code Storage. A sync from GitHub copies
only refs/heads/* and refs/tags/*. Put machine state on ephemeral branches to keep it out of
GitHub. Machine state includes agent snapshots, preview builds, and scratch commits.
Git LFS is the exception on GitHub App sync repositories: LFS uploads pass
through to GitHub from every ref, ephemeral refs included.
Related reference pages
- Create repository
- Pull from upstream
- createRepo()
- pullUpstream()
- Git LFS
- Webhooks
- Generic Sync
- Repository Forks