# Git-LFS

Swarmfile can act as a **git-LFS server**. Keep your source in the git host you already use - GitHub, GitLab, or self-hosted - and route only the large binary assets to Swarmfile, where they get real storage, deduplication, encryption at rest on a managed repository, and quota instead of bloating your git remote. LFS objects count as storage on your plan - deduplicated like drive content - and downloads are free.

This is the lowest-friction way to start: nothing about your VCS or your team's workflow changes. You keep `git push`; `git lfs push`/`pull`/`checkout` move the big files through Swarmfile.

> The fuller destination is making Swarmfile the home for the *whole* repository - native version control on a drive you mount, with no clone at all (see [Coming from Git](https://swarmfile.com/docs/guides/coming-from-git) and [Version Control](https://swarmfile.com/docs/guides/version-control)). The LFS bridge is where you start; you can move the rest at your own pace.

## Which repositories it works on

git-LFS works on **managed-key** and **unencrypted** repositories. It is **not** available on end-to-end-encrypted repositories: a stock `git-lfs` client can't hold a per-user encryption key, and the hub structurally can't read end-to-end content, so there is no one to encrypt or decrypt for. An LFS request against an E2E repository is refused up front with a `422` and a clear message rather than failing silently per object. See [End-to-End Encryption](https://swarmfile.com/docs/admin/end-to-end-encryption) for what that tier trades off.

**On a managed repository, uploads must use the Swarmfile transfer agent.** The agent uploads the object as small content-addressed blocks, which the hub encrypts at rest (the Desktop App's built-in agent seals them client-side; the standalone `swarmfile-lfs` agent's blocks are encrypted by the hub on write). The stock direct paths - a plain `git-lfs push`, a hand-crafted direct object PUT - are refused with a `422` and the typed error `lfs_agent_required`, because they would store the object as one unencrypted object. Install the agent once per machine (step 3 or [Pushing large files](#pushing-large-files)) and retry.

| Repository | Stock `git-lfs push` (direct) | Transfer agent (chunked) |
|---|---|---|
| Managed-key | **Refused** (`lfs_agent_required`) | **Encrypted at rest**, any size |
| Unencrypted (keyless / Free / public-visibility) | Allowed - plaintext by definition | Allowed - plaintext by definition |
| End-to-end | Refused (`422`; LFS is unsupported) | Refused (`422`; LFS is unsupported) |

An **unencrypted** repository - every Free-plan repository and every public repository on any plan - is plaintext on every path by definition. Objects pushed through the chunked agent path also deduplicate against the same content on your mounted drive.

> **Older objects.** The agent requirement applies to new uploads. A managed repository that took stock pushes before this rule may still contain objects written the old, plaintext way until its operator-run migration reports clean - the hub converts each one to encrypted storage and verifies the bytes before removing the plaintext copy, and the migration is only clean when no plaintext candidate (including an object too large for its default per-object cap) remains. Until that migration reports clean for the repository, don't assume every existing LFS object is encrypted. Uploads started after the rule took effect are encrypted; a presigned single PUT admitted before the rule landed can still complete as an older plaintext object, but a multipart session created before the rule cannot complete - its part and complete requests answer the same `lfs_agent_required` 409 and abort the session. (End-to-end repositories never supported LFS at all.)

Importing an existing repository that uses git-LFS isn't supported: [`swarmfile git import`](https://swarmfile.com/docs/cli/swarmfile#git-import) refuses a default branch that carries LFS pointers and skips a side branch that does (see [Known Limitations](https://swarmfile.com/docs/reference/known-limitations#importing-an-existing-repository-converts-or-skips-some-git-shapes)). Keep the repo on its current host and use the LFS redirect below instead.

## Setup

### 1. Generate a git-LFS credential

In the dashboard, open your repository → the **git-LFS** tab → **Generate git-LFS credential**. This mints a repository-scoped API key (an `sf_key_…` string). Treat it like a password; it grants access to this one repository's files. It counts against your plan's headless-seat allowance (Free 1; Starter 2 per seat, minimum 5; Pro 5 per seat, minimum 10; Studio 10 per seat, minimum 20) - if the mint is refused, revoke an unused key or add a headless seat under Settings → Billing. One key per repository is the natural pattern: reuse it for that repository's LFS, CI, and scripts rather than minting a fresh one each time.

### 2. Commit `.lfsconfig`

The panel shows an `.lfsconfig` block. Commit it to the root of your repo so every clone points its LFS traffic at Swarmfile:

```ini
[lfs]
  url = https://hub.swarmfile.com/orgs/<org>/lfs/<repository>
```

The URL encodes your org and repository, so there's no coupling to your git remote - the git remote stays exactly where it is.

Keep it to just the `url`: `git-lfs` only accepts a small safe allowlist of keys in a repo-committed `.lfsconfig` and prints a `warning: These unsafe '.lfsconfig' keys were ignored` line for anything else - per-machine settings (the large-download retry window, credentials) go in `git config` in the next step instead.

### 3. Store the credential

`git-lfs` authenticates over **HTTP Basic**. Run the setup once per clone: register git-lfs's filters (without this, `git add` commits the raw bytes instead of an LFS pointer), store the `sf_key_…` in your git credential store as the **password** (the username can be anything), tell git-lfs to use basic auth directly so it skips a 401-probe round trip on every call, and widen the large-download retry window (see [Large files](#large-files)):

```bash
git lfs install

# Store the credential (username arbitrary, password = your sf_key_…)
git credential approve <<EOF
protocol=https
host=hub.swarmfile.com
username=swarmfile
password=sf_key_…
EOF

# Use basic auth for this endpoint without the 401 probe
git config lfs.https://hub.swarmfile.com/orgs/<org>/lfs/<repository>.access basic

# Per-machine: how many times a large download retries while it's prepared.
# (.lfsconfig can't carry this - git-lfs ignores non-allowlisted keys there.)
git config lfs.transfer.maxretries 240

# Required on a managed repository: wire git-lfs to the Swarmfile transfer
# agent (bundled with the Desktop App; otherwise install it once - see
# "Pushing large files"). Optional on an unencrypted repository.
swarmfile-lfs install
```

The "Generate git-LFS credential" panel emits this snippet with your real org, repository, and key filled in - copy it from there; it has a **Windows (PowerShell)** tab for machines where bash is not available. A `~/.netrc` entry (`machine hub.swarmfile.com login swarmfile password sf_key_…`) works too if you prefer.

On Windows, run the same setup from PowerShell instead - the credential step uses a here-string, since `<<EOF` is bash-only:

```powershell
git lfs install

@'
protocol=https
host=hub.swarmfile.com
username=swarmfile
password=sf_key_…
'@ | git credential approve

git config lfs.https://hub.swarmfile.com/orgs/<org>/lfs/<repository>.access basic
git config lfs.transfer.maxretries 240

# Required on a managed repository (the Desktop App bundles it; otherwise
# install it once - see "Pushing large files").
swarmfile-lfs install
```

### 4. Track and push

From here it's the usual git-LFS commands; on a managed repository the transfer agent you installed handles the upload:

```bash
git lfs track "*.psd" "*.exr" "*.uasset"   # writes .gitattributes
git add .gitattributes
git add my-big-file.psd
git commit -m "Add art source"
git push            # source objects to your git host
git lfs push        # big files to Swarmfile
```

Teammates who clone the repo get the committed `.lfsconfig`, add their own credential once (step 3), and `git lfs pull` fetches the big files from Swarmfile.

![git-LFS pointed at Swarmfile through the helper and the swarmfile-lfs agent: a 25 MB level file goes in as a pointer, and a second clone returns it byte-identical - the two SHA-256 lines are the evidence.](https://swarmfile.com/demo/oss-git-lfs.cast)

## Or let the GitHub App do it

Everything above works with any git host and any git-lfs client. If your remote
is GitHub, the repository's git-LFS tab can do part of it for you (the git-LFS tab
installs the Swarmfile GitHub App and opens the setup pull request; the manual
steps above always work). If you belong to more than one organization, the install page
asks which one to link the installation to - one installation maps to one
Swarmfile organization:

- **Install the GitHub App** - click the button in the tab, pick the
  repositories to let Swarmfile see, and come back. One installation per
  Swarmfile organization.
- **Route a repository** - in the same tab, choose the repository and click
  **Route this repo to `<repository>`**. That links it to the repository (each repo
  gets its own `.lfsconfig`, because the URL embeds the repository id).
- **Open setup PR** - Swarmfile opens a small pull request that adds
  `.lfsconfig` to the repository. Merge it (or close it and use the manual
  steps above - nothing is forced).
- **Mint git-LFS credential** - the tab mints a repository-scoped `sf_key_…` for
  you and shows the same per-clone commands as step 3, prefilled.
- **Filter or bulk-link** - an installation with many repositories gets a filter
  box and a **Link all shown** action, so you don't link them one at a time.
- **Re-run reflect** - if a push's automatic reflect misses (a very large push,
  or an object that was still being verified), the repository row's **Re-run
  reflect** runs it again from the branch head.
- **Mirror releases** - the repository row's checkbox mirrors this repository's
  future ready releases (tag, notes, attached assets) to the GitHub repo as
  GitHub Releases. Off by default, one-way, idempotent; unpublishing a release
  here deletes its mirrored GitHub release. A CI-driven team can instead paste
  a workflow that calls the mirror endpoint with a repository API key on
  `release: published` - the same idempotent mirror, so the two never
  conflict:

  ```yaml
  name: Mirror releases to GitHub
  on:
    release:
      types: [published]
  jobs:
    mirror:
      runs-on: ubuntu-latest
      steps:
        - name: Ask Swarmfile to mirror this release
          run: |
            curl -fsS -X POST \
              -H "Authorization: Bearer ${{ secrets.SWARMFILE_API_KEY }}" \
              "https://hub.swarmfile.com/orgs/${{ vars.SWARMFILE_ORG_ID }}/repositories/${{ vars.SWARMFILE_REPOSITORY_ID }}/releases/${{ github.event.release.tag_name }}/mirror" \
              && echo mirrored
  ```

  The endpoint accepts the release **tag** (as above) or its release id. The
  API key must belong to an organization owner or admin - the mirror route is
  owner/admin-gated. (The scheduled sweep is the belt-and-braces: a missing
  or failing workflow cannot leave the mirror behind.)

After that, `git lfs push`/`pull` work exactly as described above, and **agent-pushed objects show up on the mounted drive automatically** - a push webhook reflects the pushed branch's objects onto the repository's matching Swarmfile branch, so you don't need to run `swarmfile-lfs reflect` by hand.

On the machine that pushed, the file appears on the drive within moments as an optimistic preview; the hub's reflect then confirms it, or withdraws the preview if it refuses the mapping (a path conflict, or a folder you can't write to). Teammates see the file once the hub reflect lands. (Objects pushed by a *stock* `git-lfs` client are pull-able but not reflected - see the note under [Deduplication and the mounted drive](#deduplication-and-the-mounted-drive).)

The App is provisioning-only: it never sees or proxies your LFS objects, and the credential stays the `sf_key_…` you minted - uninstalling the App doesn't break clones that already have their credential.

## Deduplication and the mounted drive

Swarmfile stores content once. If two people push the same bytes - or the same object already exists - the second upload is skipped, exactly as LFS dedup is meant to work. One exception: when the bytes so far exist only as a file saved on the drive, the first push uploads them anyway, and Swarmfile checks the drive copy in the background; once it's confirmed, later pushes of the same bytes are skipped.

It goes one step further: a file saved to the **mounted Swarmfile drive** through the desktop app is `git lfs pull`-able by its object id, with **zero duplicate storage**. (So is a file added through the web dashboard's uploader. A file saved before object ids were recorded can be given one with `swarmfile git backfill-oids`.) The LFS object *is* the native content - the same bytes the drive already holds, addressed two ways. So a file your team produced on the drive can be pulled by a git-LFS client that only knows its `oid`, without storing it twice.

That holds for any version the repository still keeps: a drive version that has aged out of your history retention is gone for LFS too, and a pull of it reports the object as missing. On the default **Keep every saved version** repositories a drive version doesn't age out, so its LFS object stays pull-able while the version is retained.

Pushing or re-pushing an object with `git lfs push` makes it an LFS object in its own right, kept independently of drive retention.

It doesn't apply to end-to-end encrypted repositories (no LFS at all), nor to content encrypted with a static key you supply yourself (`SWARMFILE_ENCRYPTION_KEY`): in both cases the hub holds no key, so Swarmfile never sends it a file's SHA-256 object id.

The reverse direction works too, with one manual step. An object pushed with `git lfs push` can be **projected onto the mounted drive** as a first-class file at its repo path - reusing the blocks the push already stored (again, zero duplicate storage). Because the LFS protocol only ever sends an object's *id*, never its path, the file's path comes from your git working tree, so you run one command after pushing:

```bash
git lfs push origin main
swarmfile-lfs reflect            # repositories the just-pushed objects onto the drive
```

`reflect` reads `git lfs ls-files`, sends the oid→path map to Swarmfile, and the hub creates the drive entries. It mirrors your current git branch onto a same-named Swarmfile branch (auto-created; override with `--branch`), and it **never overwrites** a file already on the drive - a path already occupied by different content is reported as a conflict and left alone. Re-running it is safe (already-projected files report as unchanged). (If you run the desktop app rather than the standalone binary, `swarmfile-engine reflect` is the identical command.) To make it automatic, wire it into a `git push` alias:

```bash
git config --global alias.pushr '!git push "$@" && swarmfile-lfs reflect'
# then: git pushr origin main
```

After reflection, that path has a real drive entry - so it's reachable through *both* surfaces (drive + LFS), participates in mount worksharing locks, and appears for teammates on the drive.

> **Reflection needs the transfer agent.** `reflect` maps an object onto the drive only when Swarmfile stored it as content it can address - i.e. the object was pushed through the transfer agent (above) or the desktop app. On an unencrypted repository, a plain **stock `git-lfs push`** takes the direct-upload path: the object is stored and `git lfs pull`-able, but it isn't a drive manifest, so `reflect` reports it as `missing`. (On a managed repository a stock push is refused; use the agent, whose objects reflect normally.) If a file must appear on the mounted drive, install the agent (see [Pushing large files](#pushing-large-files)) and push through it, or write the file to the drive directly. The GitHub App's automatic reflect has the same dependency.

Reflection is **additive**: it creates or leaves-alone, and never deletes. Removing or renaming a file in git won't remove or move its drive entry - do that on the drive (or via the dashboard). It enforces the same **write** permission a drive write does: on a repository with per-folder access rules, reflecting a file into a folder you can't write to is refused (reported as `denied`) and skipped.

A very large push reflects a **bounded number of objects per run** (a whole-tree scan is capped for cost). The rest land on the next push - or immediately, via another `swarmfile-lfs reflect` (or the tab's **Re-run reflect**). The cap is noted in the row's status when it applies.

## Large files

### Downloading large files

Small and mid-sized objects download immediately. A **very large** object (roughly a gigabyte or more) is prepared on its **first** download: Swarmfile assembles it into a single downloadable copy in the background, and until that finishes `git lfs pull` waits and retries automatically - you'll see it pause, then complete.

This is why step 3 sets `git config lfs.transfer.maxretries 240`: it gives the client enough patience to wait through preparation. Once prepared, that copy is reused, so subsequent pulls of the same object are immediate.

Under the hood, an attempt while preparation is still running gets `429 Too Many Requests` with a `Retry-After` interval - that pause is git-lfs honoring the retry - and a preparation that fails for good gets `502` naming the reason rather than looping the client on 429.

If a pull of a very large object ever gives up with a "being prepared, retry" message, just run `git lfs pull` again - preparation continues in the background and the retry will pick up the finished copy. A `502` is different: preparation failed permanently and the message says why, so retrying won't change the outcome until the underlying cause clears. (Raising `lfs.transfer.maxretries` further with `git config` widens the wait window if you routinely pull multi-gigabyte objects. It has to be `git config`, not `.lfsconfig` - git-lfs ignores that key in a committed config file.)

### Pushing large files

On an **unencrypted** repository a plain `git lfs push` sends each object in a single request, supporting objects up to about 5 GiB. On a **managed** repository the transfer agent is required for every upload; it also lifts the size boundary, sending chunked, resumable blocks (up to 256 GiB per object).

Install the **Swarmfile transfer agent**: a small (~2 MB), standalone, open-source binary (`swarmfile-lfs`) that speaks git-lfs's documented [custom-transfer protocol](https://github.com/git-lfs/git-lfs/blob/main/docs/custom-transfers.md). Its FastCDC chunker and the block/manifest wire format are open source too, published with the agent at [swarmfile-lfs](https://swarmfile.com/public/swarmfile/swarmfile-lfs).

No desktop app required - but if you already run the desktop app, it's already installed (every desktop installer bundles it on `PATH`), so skip the download and go straight to `swarmfile-lfs install`.

```bash
# 1. If the desktop app is installed, the agent is already on PATH - skip to
#    step 2. Standalone install:
cargo install swarmfile-lfs-transfer    # any Rust toolchain; installs the swarmfile-lfs binary
curl -fsSL https://get.swarmfile.com/lfs | sh             # macOS / Linux
#    Windows (PowerShell):  irm https://get.swarmfile.com/lfs.ps1 | iex
# …or download the binary for your platform from the public release:
#    https://swarmfile.com/public/swarmfile/swarmfile-lfs
#    (No Homebrew formula; use cargo or the installer above.)

# 2. Wire git-lfs to it, once per machine:
swarmfile-lfs install
```

> Those standalone channels ship separately from the app, so the dashboard's install command is the authoritative one for your account. If you already run the desktop app, `swarmfile-lfs` is installed on `PATH` with it, and the app also bundles an equivalent built-in agent (`swarmfile-engine lfs-transfer`; on a managed repository its large-object fast path is unavailable, so it falls back to the same encrypted block upload).

`swarmfile-lfs install` just writes the git-lfs custom-transfer adapter config for you (add `--local` to scope it to the current repo instead of your global config; `swarmfile-lfs uninstall` undoes it in the same scope).

With it in place, `git lfs push` transparently uploads large files as small content-addressed blocks - encrypted at rest on a managed repository (the built-in agent seals blocks client-side; the standalone agent's blocks are encrypted by the hub on write) - up to **256 GiB per object** (and your repository quota), deduped against the same content on your Swarmfile drive.

Nothing else changes: `git lfs push`/`pull` work unchanged, the agent only kicks in for uploads, and it authenticates with the same credential you stored in step 3 (so make sure that's done on each machine that pushes large files).

On an unencrypted repository, stock `git lfs push` still works up to about 5 GiB per object without the agent. On a managed repository the agent is required - a stock push is refused with `lfs_agent_required` - and any file is always available by writing it to the mounted drive instead.

If you already run the **Swarmfile desktop app**, `swarmfile-lfs` is already on `PATH` - `swarmfile-lfs install` is all you need.

The engine also exposes an equivalent built-in agent as `swarmfile-engine lfs-transfer`, if you'd rather point git-lfs at that (`git config lfs.customtransfer.swarmfile-chunked.path swarmfile-engine` / `.args lfs-transfer`). (Both agents encrypt at rest on a managed repository; they differ only in where the encryption happens - client-side in the built-in agent, on the hub for the standalone agent's blocks.)

**An interrupted large push is safe to re-run.** Just run `git lfs push` again: content-addressed blocks the agent already uploaded are deduplicated, and the desktop app's built-in agent additionally resumes a ≥ 64 MiB multipart upload from the parts that already landed instead of starting over. Nothing is left behind either way - an upload nobody resumes is reaped server-side after 7 days on Swarmfile-managed storage.

## What's supported

- The LFS **Batch API** (`upload` and `download`) and the **basic transfer** adapter - the operations `git lfs push`, `pull`, `checkout`, and `fetch` use.
- **Verify**, so a truncated upload is caught rather than silently stored.
- **Locking** (`git lfs lock` / `git lfs locks` / `git lfs unlock`), for every tracked path - including files that live **only** in your git host and have never been written to the Swarmfile drive. When a path *does* also exist on the drive, its LFS lock and its desktop/mount worksharing lock are the **same** server-side lock, so locking via `git-lfs` and locking on the drive mutually exclude, across machines and across both surfaces. The path resolves on the branch `git-lfs` reports (its `ref` - the checked-out branch) whenever Swarmfile has that branch; otherwise it falls back to the repository's default branch, so an LFS-only repo whose git feature branches have no Swarmfile counterpart keeps working as before. A path the resolved branch's tree doesn't have - a file that exists only in git, or one missing from that branch - takes the branch-less advisory lock below. Lock listing and push verification scope entry locks the same way - a drive lock taken on a feature branch doesn't block a push to `main` - while the branch-less advisory lock applies to every branch. The advisory lock is what other `git-lfs` clients see; unlocking is owner-gated (use `--force` to break another user's lock). Locks hold for 30 days and nothing renews a git-side lock, so a lapsed one releases itself rather than staying stuck - take it again if the work outlives that. See [Working with Files](https://swarmfile.com/docs/guides/working-with-files).

## Performance

Upload throughput is bounded by *your* connection to Swarmfile, so no headline number is meaningful. Two properties hold regardless of uplink:

- **The chunked agent is faster for large objects**, because it sends many ~1 MiB blocks in parallel instead of one large request.
- **Re-pushing an unchanged object transfers nothing** - git-lfs sees the server already has the object and skips it, so a re-push costs one batch round-trip (well under a second) no matter the file's size.

## Continuous integration (CI)

Two things make CI painless, and they split by direction:

- **Pulling assets needs no agent for almost everything.** `git lfs pull`/`fetch`/`checkout` works with the stock git-lfs that's already on every runner; large objects materialize and retry (that's what the `lfs.transfer.maxretries` setting below is for). One boundary: a very large object's first *stock* download may be paced - the hub answers with a "wait, preparing" and the retry setting carries the client through. Uploads are the direction that needs the agent - on a managed repository every upload does, and for an unencrypted repository it lifts the ~5 GiB boundary. A build or test job needs only credentials.
- **Pushing objects needs the agent on a managed repository**, and needs it for objects over ~5 GiB on an unencrypted one. A release or asset-generating job adds one install step.

In both cases, store the repository's `sf_key_…` as a CI secret (`SWARMFILE_API_KEY`) and feed it to git through a credential helper. Never bake the key into `.lfsconfig` or a command line.

### GitHub Actions

**Pull-only job** (build/test - no agent):

```yaml
env:
  SWARMFILE_API_KEY: ${{ secrets.SWARMFILE_API_KEY }}
steps:
  - uses: actions/checkout@v4
    with: { lfs: false }            # skip the auto-smudge; we pull explicitly below
  - name: Configure Swarmfile LFS credentials
    run: |
      git config --global credential.helper \
        '!f() { test "$1" = get && printf "username=lfs\npassword=%s\n" "$SWARMFILE_API_KEY"; }; f'
      git config --global lfs.transfer.maxretries 240   # wait through large-object preparation
  - run: git lfs pull                # any size the hub can assemble; a very large object may ask the client to wait while it prepares
```

**Push job** (release/asset generation - installs the agent). If you can't use the `get.swarmfile.com` installer (a restricted network, or a policy against piping a download to a shell), download `swarmfile-lfs` from the [downloads page](https://swarmfile.com/downloads) or copy it off a machine with the desktop app, and substitute that path for the `curl` step:

```yaml
env:
  SWARMFILE_API_KEY: ${{ secrets.SWARMFILE_API_KEY }}
  SWARMFILE_LFS_URL: https://hub.swarmfile.com/orgs/<ORG>/lfs/<REPOSITORY>
steps:
  - uses: actions/checkout@v4
  - name: Install the Swarmfile transfer agent
    run: |
      curl -fsSL https://get.swarmfile.com/lfs | SWARMFILE_LFS_BINDIR="$HOME/.local/bin" sh
      echo "$HOME/.local/bin" >> "$GITHUB_PATH"
      swarmfile-lfs install         # writes the git-lfs custom-transfer config (global)
  - name: Configure Swarmfile LFS credentials
    run: |
      git lfs install                 # register the clean/smudge filters on this runner
      git config --global credential.helper \
        '!f() { test "$1" = get && printf "username=lfs\npassword=%s\n" "$SWARMFILE_API_KEY"; }; f'
      git config --global "lfs.${SWARMFILE_LFS_URL}.access" basic
      git config --global lfs.transfer.maxretries 240
  - run: git lfs push origin HEAD   # all objects go through the agent (required on managed)
```

### GitLab CI

```yaml
push-assets:
  image: ubuntu:22.04
  variables:
    SWARMFILE_LFS_URL: https://hub.swarmfile.com/orgs/<ORG>/lfs/<REPOSITORY>
  before_script:
    - apt-get update && apt-get install -y git git-lfs curl ca-certificates && git lfs install
    - curl -fsSL https://get.swarmfile.com/lfs | SWARMFILE_LFS_BINDIR=/usr/local/bin sh
    - swarmfile-lfs install
    - git config --global credential.helper
        '!f() { test "$1" = get && printf "username=lfs\npassword=%s\n" "$SWARMFILE_API_KEY"; }; f'
    - git config --global "lfs.${SWARMFILE_LFS_URL}.access" basic
    - git config --global lfs.transfer.maxretries 240
  script:
    - git lfs push origin HEAD
  # Set SWARMFILE_API_KEY as a *masked, protected* CI/CD variable - not in this file.
```

The credential helper reads `SWARMFILE_API_KEY` at the moment git invokes it, so the secret never lands on a command line or in the log. For a pull-only job you can drop the agent install and the `access basic` line entirely.

## Leaving Swarmfile

Your source lives in your own git host and never touches Swarmfile - so leaving is only ever about pulling your binary objects back out, and that works with **stock git-lfs and no Swarmfile software installed at all**. There is no export API to learn and no proprietary format to unwind.

```bash
# In a clone that points at Swarmfile, pull every version of every object
# referenced by any branch or tag into your local .git/lfs/objects store:
git lfs fetch --all

# Confirm you hold complete, uncorrupted copies (each object hashes to its oid):
git lfs fsck
```

After `git lfs fetch --all`, every object is on your disk. To move them to another LFS server, point the repo at the new endpoint and push:

```bash
git config -f .lfsconfig lfs.url https://your-new-lfs-server/…   # GitHub, GitLab, S3-backed, self-hosted, anything
git lfs push --all <remote>
```

This is deliberately the *standard* git-lfs export path - the custom-transfer agent is only an optional accelerator for large **uploads**; nothing about your objects is locked to Swarmfile software. You can walk away with a single command, which is exactly the point: your binaries are as portable as your git history.

## Troubleshooting

**A `warning: These unsafe '.lfsconfig' keys were ignored` line.** Something other than `lfs.url` is in the committed `.lfsconfig` (often `lfs.transfer.maxretries`). git-lfs only accepts a safe allowlist in a repo-committed config file and ignores the rest by design; move per-machine settings to `git config` (step 3 shows the retry one). The warning is about the ignored key, not a failed transfer.

**A `401` on every LFS call.** Credential helpers disagree about whether the key belongs in the username or the password field; Swarmfile accepts the `sf_key_…` in **either**, but the safest placement is the password. Re-run the `git credential approve` step above, and confirm you set `…access basic` so git-lfs sends the header on the first request.

**A `422` for every object (`lfs_agent_required`).** The repository is managed/encrypted, and the push is using the stock direct path. Run `swarmfile-lfs install` (the Desktop App bundles the agent), then retry. On an unencrypted repository this error does not apply.

**A `422` for every object (not `lfs_agent_required`).** The repository is end-to-end encrypted, which git-LFS can't support (see above). Use a managed or unencrypted repository, or move the source-plus-assets to a mounted drive instead.

**`git lfs pull` fetches nothing / objects are missing.** Confirm `.lfsconfig` is committed and its `url` names the right org and repository, and that the credential you stored is for that same repository.

**`git lfs unlock` fails on a lock someone else holds.** Path locks are owner-gated: only the user who took a lock can release it normally. Pass `--force` (or `--id <id> --force`) to break another user's lock, or ask them to unlock it. `git lfs locks` shows the current holder of every live lock.
