Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

All docs

Set up Git sync Agency plan

Agency · Git sync is part of the Agency plan (and its free trial). Plans

Setting up takes about ten minutes: create a repository, create an access token, enter both in WordPress, sync.

1. Create a repository

Create an empty repository on GitHub or GitLab (or use an existing one). Make it private: snippets can contain things you don't want public.

Snipfire only touches its own files in the folder you choose (by default snipfire/), so a repository that holds other things too is fine. For large repositories, a repository (or branch) just for snippets is faster.

2. Create an access token

The token lets your site read and write the repository. Give it access to that repository only.

GitHub: create a fine-grained personal access token:

  1. GitHub → Settings → Developer settings → Personal access tokens → Fine-grained tokens → Generate new token.
  2. Repository access: Only select repositories, pick your snippets repository.
  3. Permissions → Repository permissions → Contents: Read and write.
  4. Choose an expiry date and put a reminder in your calendar to renew it.

For an organisation's repository, the organisation may need to allow fine-grained tokens first.

GitLab: create a project access token in the project: Settings → Access tokens, role Developer, scope api.

3. Enter the settings

Go to Snipfire → Tools & Safe Mode → Git sync (or Git sync in the editor's sidebar, then Settings).

Setting What to enter
Host GitHub or GitLab
Repository owner/name, for example acme/snippets, or paste the repository's web or clone address. On GitLab, subgroups work: group/subgroup/project
Branch Usually main. If it doesn't exist yet, the first sync creates it from the repository's default branch
Folder in the repository Where the snippets go. Default snipfire. Leave empty for the top of the repository
What to sync Leave empty for every snippet, or enter a Snipfire folder (for example Shared) to sync only that folder and its subfolders
Access token The token from step 2. It's stored encrypted and never shown again
Sync automatically No, only when I click Sync now, Every hour, Twice a day or Once a day. See Automatic sync
Self-hosted Only for GitHub Enterprise Server or your own GitLab: the API address, for example https://github.example.com/api/v3 or https://gitlab.example.com/api/v4

Click Save Git settings, then Test the connection. You should see Connected to acme/snippets, branch main. (or …Branch main doesn't exist yet: the first sync creates it.).

Keeping the token out of the database

Instead of entering the token in the form, you can put it in wp-config.php:

define( 'SNIPFIRE_GIT_TOKEN', 'github_pat_…' );

The settings then show Set in wp-config.php (SNIPFIRE_GIT_TOKEN). A token saved in the form is encrypted with a key derived from your site's secret keys (in wp-config.php), and it's never sent to the browser. If those secret keys change, Snipfire can't read the saved token any more and asks you to enter it again.

4. Sync

Click Sync now.

  • Empty repository or folder: all your snippets (or the chosen folder's) are written to Git in one commit.
  • Snippets already in Git (for example, you're connecting a second site): matching snippets are recognised, snippets only in Git are created on the site, snippets only on the site are pushed. Snippets that exist on both sides but differ are shown as conflicts for you to settle. See How syncing works.

The Git sync view then shows Last sync with OK, how many snippets are synced, Open the repository and View the commit.

From the command line

wp snipfire git setup --provider=github --repo=acme/snippets --token=github_pat_… --check
wp snipfire git sync

setup only changes the options you give. See Automatic sync, webhooks and WP-CLI.

Changing the settings later

Changing the repository, branch, folder or what to sync starts afresh: the next sync compares the site and Git from scratch. Snippets that match are recognised; snippets that differ appear as conflicts. Nothing is overwritten without asking.

Something unclear or missing? Tell us