# git-remote-swarmfile

`git-remote-swarmfile` is the small **git remote helper** behind `git clone`, `git fetch` and `git push` on a `swarmfile://` URL. Git invokes it by name whenever it sees a `swarmfile://` remote, so you never run it yourself. The desktop build re-execs the engine binary in `git-remote` mode; either build needs no running engine, no drive and no mount.

Every desktop installer puts it on `PATH` beside `swarmfile` (on macOS, `/usr/local/bin`; on Linux, `/usr/bin`). On a machine without the app, install the open-source standalone helper with `curl -fsSL https://get.swarmfile.com/git-v | sh` (Windows: `irm https://get.swarmfile.com/git-v.ps1 | iex`); source and releases are at [swarmfile-git-remote](https://swarmfile.com/public/swarmfile/swarmfile-git-remote).

The standalone build has no built-in LFS transfer agent; pair it with [`swarmfile-lfs`](https://swarmfile.com/docs/guides/git-lfs#pushing-large-files) for objects over about 5 GiB.

With the desktop app installed, if `git` says it can't find a helper for `swarmfile`, use [`swarmfile git clone`](https://swarmfile.com/docs/cli/swarmfile#git-clone), which finds the helper next to the `swarmfile` binary even when it isn't on `PATH`; with the standalone build, put its install directory on `PATH`. Git 2.11 or later is required.

![An owner enables a repository's git surface with one command; an ordinary git clone speaks swarmfile:// through the helper; a commit pushes fast-forward; and swarmfile-verify-history walks the chain it just created.](https://swarmfile.com/demo/oss-git.cast)

## How git uses it

```bash
git clone swarmfile://<org>/<repository>                    # the configured hub
git clone swarmfile://<hub-host>/<org>/<repository>         # a specific hub
git clone swarmfile://<hub-host>/fed/<peer>/<org>/<repository>  # a federated public read
git remote add origin swarmfile://<hub-host>/<org>/<repository>
git fetch origin
git push origin main
```

The host-qualified form names the authority, so a copied link means the same repository on every machine that can reach that host; the relative form resolves against the receiving machine's configured hub (`SWARMFILE_HUB_URL`, or the Desktop App sign-in in the desktop build).

An authority is `host[:port]`; **the org segment is required** - `swarmfile://<hub-host>/<repository-id>` is read as a relative URL whose org is the host, not as a repository on that host.

The grammar carries no scheme: the helper uses HTTPS by default, and HTTP only for loopback or an authority listed in `SWARMFILE_GIT_INSECURE_HOSTS`.

A renamed repository or org keeps the old slug as a reserved alias, so an old clone URL keeps resolving for a session, an anonymous public clone, or a repository key on a **public** repository (the directory carries aliases); a keyed **private** remote should use the ids.

The four-segment `fed` form reads a **public plaintext repository through a federating server**: `swarmfile://<hub-host>/fed/<peer>/<org>/<repository>`. `<peer>` is a name pinned on `<hub-host>`, not an org or a URL; the repository lives on that peer and must be exported to `<hub-host>`. The session is anonymous and read-only by construction - an ambient or stored credential is **not** sent, git-LFS **downloads** are carried through the federator (uploads and locking are not), and a push is refused with a typed read-only reason. The federating server carries the origin's bytes and signed history unchanged (no re-signing, no byte cache).

`<repository>` may be a bare repository name or a repository id. A bare name is qualified with the configured organization by `swarmfile git url` / `swarmfile git clone`. Git access is turned on per repository - from the web repository menu, the Desktop App's **Repository settings → Git access**, or `swarmfile git enable` - and a clone of a repository that hasn't enabled it is refused with `no_git_view`; the org's owners are nudged once, and `swarmfile git status` shows where a repository stands.

## What it serves

Shallow clones with `--depth`, fetches, fast-forward pushes (merges land on auto-archived `merged/<sha>` branches), lightweight tag moves and deletes, and chunked resumable pushes above 5,000 paths.

Force push is refused by default for an older clone - a clone created through the helper sets `swarmfile.force-forward=true`, translating plain `--force`/`--force-with-lease` into a forward commit (the same end state [`swarmfile git force-forward`](https://swarmfile.com/docs/cli/swarmfile#git-force-forward) lands); an explicit `git config swarmfile.force-forward false` keeps the refusal.

- Submodule gitlinks are carried as mode `160000` (the drive hides the submodule path).
- End-to-end-encrypted repositories are supported when `SWARMFILE_USER_KEY_PRIVATE_B64` and `SWARMFILE_USER_KEY_ID` name this device's enrolled user key (the helper unwraps the repository key locally; the view is all-inline).
- Direct HTTPS remotes on the hub are refused (an operator can run the read-only `swarmfile-git-gateway` for stock public clones).
- Annotated tags keep their exact object, and an octopus merge is accepted when every parent after the second is already on Swarmfile.
- `--shallow-since`/`--shallow-exclude` aren't supported.

The full list, and the version-control model around it, is in [Clone and push with git](https://swarmfile.com/docs/guides/git-clone) and [Git and Swarmfile](https://swarmfile.com/docs/guides/git-and-swarmfile).

## Credentials

The **standalone build** reads its credential only from `SWARMFILE_API_KEY` (a repository API key or a personal access token), plus `SWARMFILE_HUB_URL` and `SWARMFILE_ORG_ID` when the URL names no host or org. With `SWARMFILE_API_KEY` unset it makes an anonymous public clone (below); the URL must then carry both the org and the repository slug.

The **desktop build** looks for, in order:

1. **`SWARMFILE_API_KEY`** in the environment. A repository API key wins over everything else, including a Desktop App session, and the helper says so when both are present.
2. **A Desktop App session** stored by the engine.
3. **A repository API key in git's credential store**, stored with `git credential approve` for the Swarmfile host.

An explicit `SWARMFILE_API_KEY` is global. For a host-qualified URL that names a different authority than `SWARMFILE_HUB_URL`, it is sent only when `SWARMFILE_ALLOW_CROSS_HUB_KEY=1`; otherwise the helper falls back to a git credential stored for that host, or the anonymous path.

With `SWARMFILE_HUB_URL` unset, the key is still **not** offered to an explicit host unless `SWARMFILE_ALLOW_CROSS_HUB_KEY=1` - the URL alone does not authorize a global key (the engine helper enforces the same rule).

An old public repository slug resolves through the hub's one-request `/public/<org>/_resolve/<repository>` route; a keyed push over an old **private** slug still needs the id or a signed-in session. The stored Desktop session and the key a self-hosted install saved for its server are never offered to another authority.

With none of these the helper falls through to an **anonymous public clone** when the repository allows it - a public, git-enabled repository with anonymous cloning on (the default; see [Clone and push with git](https://swarmfile.com/docs/guides/git-clone)).

That clone is read-only, shallow unless `--depth`/`--unshallow` ask otherwise, and pulls large files through a ticket-bearing LFS URL. A repository that doesn't allow it fails with the sign-in guidance instead.

The same anonymous fallthrough covers a credential that IS present but the hub refuses for the repository (a session without access to it, an expired or revoked key, a key scoped to another repository) - and a public repository the credential can't even see yet, before its first published release: the helper prints one line naming the refusal or the failed lookup, then continues as the same anonymous, read-only clone. A repository that isn't publicly cloneable keeps the refusal.

## When something goes wrong

A failed helper always prints its reason above git's `fatal: remote helper 'swarmfile' aborted session` line, and writes the same text to `git-remote-last-error.log` in the Swarmfile cache directory (`~/.cache/swarmfile` on macOS and Linux, `%LOCALAPPDATA%\Swarmfile` on Windows). The message names who can fix it; include that log in a bug report.
