# Cloning a Repository with Git

A Swarmfile repository is normally something you **mount**, not clone: the drive is live, saves sync as you make them, and there's no working copy to keep up to date. But some tools want a real git repository - a build system, a code-review or static-analysis tool, a CI job, an archive you keep offline. For those, an owner can turn on **git access** for a repository, and anyone who can read the whole repository can then:

```bash
git clone swarmfile://<org>/<repository>
```

The result is an ordinary git repository: real commits, branches and tags, with large files as git-LFS pointers that Swarmfile serves. `git fetch` brings the clone up to date, and `git push` sends your commits back as Swarmfile commits (fast-forward only - see [Pushing](#pushing)), and an existing repository can be pushed into a new repository. Starting from a repository that already exists elsewhere? [`swarmfile git import`](https://swarmfile.com/docs/cli/swarmfile#git-import) creates the repository from it in one command.

> New to how git and Swarmfile fit together? [Git and Swarmfile](https://swarmfile.com/docs/guides/git-and-swarmfile) compares this with the git-LFS server and the CLI's git-style commands.

## Turning on git access

Git access is a per-repository setting that covers every branch and tag. A repository owner or org admin turns it on:

1. In the web dashboard, open **Repositories**, use the repository's menu, and choose **Git access…**.
2. Read the warning, tick **I understand this cannot be turned off or re-tuned**, and select **Enable git access**.

The desktop app has the same switch: with the repository mounted, open **Repository settings → Git access → Enable git access…**. Or from the terminal: run [`swarmfile git enable`](https://swarmfile.com/docs/cli/swarmfile#git-enable). Both freeze the same record and print what was frozen.

Git access is off until an owner enables it. A member who tries to clone, push, or index a repository without it gets the refusal, and the org's owners and admins get one notification asking them to enable it, so the request doesn't go silent.

**It's a one-way switch.** At the moment you enable it, Swarmfile fixes the rules it uses to turn the repository into git: the conversion version, the size above which a file becomes an LFS pointer (1 MiB by default), and where history starts. Those rules never change afterward, because changing any of them would change every commit id a clone has already seen. If a different large-file boundary matters for the repo, set it in the same breath as enabling - `swarmfile git enable --threshold-bytes <N>` freezes that value instead of the 1 MiB default.

Once enabled, the dialog shows the frozen settings instead of the switch, plus the exact `git clone` command to copy. That command names the repository by its id - the form that also works on a CI machine signing in with a repository API key.

Before you enable it, two things must be true, and the hub refuses the enable (and says which) if they aren't:

- **The repository keeps every saved version.** Git access needs the repository's full history to stay restorable. Turn it on with **Keep every saved version** in the repository's history settings, or `swarmfile repository set-keep-full-history true` (see [Trash, History & Rollback](https://swarmfile.com/docs/guides/trash-history-and-rollback)).
- **Every large file has a recorded id.** A file at or above the LFS threshold reaches git as an LFS pointer, and a pointer needs the file's SHA-256. Files saved through the Desktop App get one as they're saved; older files may not. [`swarmfile git status`](https://swarmfile.com/docs/cli/swarmfile#git-status) shows how many are missing, and `swarmfile git enable` records any that are missing automatically before it freezes the view (run [`swarmfile git backfill-oids`](https://swarmfile.com/docs/cli/swarmfile#git-backfill-oids) ahead of time if you want to see the work finish first).

The enable accepts an **end-to-end-encrypted** repository through the desktop engine helper: the helper unwraps this device's repository key, the view is all-inline (E2E has no LFS), and the hub never sees plaintext. The standalone/API-key helper supports it too when given this device's `SWARMFILE_USER_KEY_PRIVATE_B64` and `SWARMFILE_USER_KEY_ID`. The enable is also refused when a branch or tag head can't be read, and when the repository's history is too long to check in one pass.

**Where history starts.** When you enable git access, Swarmfile walks back from every branch and tag. If some older commit's content is no longer stored (for example, history from before the repository kept every saved version), history is cut there: that commit appears in git as a commit with no parent. Everything from that point forward is complete.

Want to see a clone without a Swarmfile account first? The
[Zero-Install Demo](https://swarmfile.com/docs/guides/git-demo) clones a public ~60 GiB
LFS-backed repository with stock `git` over HTTPS.

## Cloning

```bash
git clone swarmfile://acme/website           # by org and repository slug
git clone swarmfile://acme/website site      # into a directory of your choice
swarmfile git clone acme/website site        # the same, through the CLI
```

The forms the URL takes:

| URL | Meaning |
|---|---|
| `swarmfile://<org>/<repository>` | The repository on the Swarmfile service your Desktop App is signed in to (or `SWARMFILE_HUB_URL`). Slugs or ids both work. |
| `swarmfile://<hub-host>/<org>/<repository>` | The same repository on a specific Swarmfile service. HTTPS, except that a loopback host (or a host an operator lists in `SWARMFILE_GIT_INSECURE_HOSTS`) may use HTTP. The org segment is required: `swarmfile://<hub-host>/<repository-id>` is read as a relative URL whose org is the host. |
| `swarmfile://<repository-id>` | A repository by its id, in your configured organization. |
| `swarmfile://<hub-host>/fed/<peer>/<org>/<repository>` | A **federated public read**: `<hub-host>` is a server that has allowlisted the origin `<peer>`, whose public plaintext repository is `<org>/<repository>`. The session is anonymous and read-only, and no local credential is sent. See [Federated public reads](#federated-public-reads). |

`swarmfile git url <repository>` prints the URL for a repository, handy for `git remote add origin "$(swarmfile git url acme/website)"`. `<repository>` can be `<org>/<repository>`, a repository id, or a bare repository name - a bare name is qualified with your configured organization.

**The printed URL names the hub** (`swarmfile://hub.example.com/acme/website`) whenever your configured hub can be written that way, so a copied link means the same repository on every machine that can reach that host (and, for a plaintext host, that also allows it); a path-prefixed or non-allowlisted plaintext hub keeps the relative form. A relative URL still resolves against whichever hub the receiving machine is configured for.

In a URL, each segment is the org's or repository's **web address** (the lowercase slug, e.g. `yadc` for a repository named YADC) or its id. A slug is matched ignoring case; when no address matches, a display name that is unique among your orgs (for the org segment) or the org's repositories (for the repository segment) also resolves - a name matching more than one is refused with the candidates listed, rather than guessed.

Renaming a repository or an org keeps the old slug as a reserved alias: an old `swarmfile://` URL keeps resolving for a signed-in session and for public/anonymous clones. A repository API key resolves an old **public** repository slug through the public directory (which carries historical slugs); a **private** repository has no public listing, so a keyed private remote should use the org/repository **ids** (the web Git access panel copies that form).

**What you need installed.** Cloning uses a small git *remote helper*, `git-remote-swarmfile`, which every Desktop App installer ships (on macOS the installer also links it into `/usr/local/bin`; on Linux it's in `/usr/bin`). No running drive is needed. If `git` says it can't find a helper for `swarmfile`, use `swarmfile git clone`, which finds the helper next to the `swarmfile` binary even when it isn't on your `PATH`. Git 2.11 or later is required.

**Standalone helper.** The open-source `swarmfile-git-remote` build (published with `swarmfile-server`) can serve the same `swarmfile://` URLs without the Desktop App. It deliberately does **not** read the app's `config.json`, so give it the hub and credential explicitly: `SWARMFILE_HUB_URL=https://hub.swarmfile.com`, an org/repository in the URL (or `SWARMFILE_ORG_ID`/`SWARMFILE_REPOSITORY_ID`), and `SWARMFILE_API_KEY`. Install it as `git-remote-swarmfile` on `PATH`; its `--help` lists the modes.

There's no branch in the URL: a clone fetches every branch and tag, with the repository's default branch as HEAD - `main` unless its default branch is something else: a different [initial branch](https://swarmfile.com/docs/guides/getting-started#creating-a-repository) at creation, or the branch an [import](https://swarmfile.com/docs/cli/swarmfile#git-import) brought with it. Use git's own options to narrow it, for example `git clone -b design-b --single-branch swarmfile://acme/website`.

### Federated public reads

Two allowlisted servers can federate **public plaintext** repository data without copying it. The origin server exports a repository to a named peer; the federating server pins that peer's signed host identity and allowlists the repository. The hosted Swarmfile service can also be one side: staff pin/import the peer and, for a hosted origin, the repository owner enables **Repository settings → Public page → Hosted federation export** on the web (see [Public repositories](https://swarmfile.com/docs/guides/public-repositories-and-org-profiles#hosted-federation-export)). A clone through the federator is anonymous and read-only:

```bash
git clone swarmfile://server-a.example/fed/server-b/acme/widget
```

- Only the origin's **public plaintext** data is served; managed/E2E repositories, ACLs, member data and keys are never federated, and no byte is copied or cached on the federating server.
- The origin's committed [`.swarmfile/publicignore.yml`](https://swarmfile.com/docs/guides/publishing-releases#keeping-paths-out-of-a-release) applies to federated reads too: if it hides a path in a served tree, the origin refuses the whole public surface with the same 404 rather than filtering the clone. See [Self-hosting → Federating public repositories](https://swarmfile.com/docs/guides/self-hosting#federating-public-repositories).
- The federator carries the origin's bytes, status and signed history unchanged - it does not re-sign anything. A portable provenance manifest written against the origin verifies against the federated clone (see [Verifiable history](https://swarmfile.com/docs/guides/verifiable-history)).
- git-LFS **downloads** are carried through a federated read (the origin's object store is served through the federator); LFS **uploads and locking** are not federated. If a clone cannot fetch an LFS object, clone from the origin or use its release archive.
- A federated read cannot push. To contribute, clone from the origin with a credential and push there.
- The origin URL is unlisted, but the repository is public: exporting it makes its public reads answerable to anyone who knows the URL. An operator can additionally require a signed request from the federating peer (`admin federation repository allow --export --require-actor`); then only the federator's signed reads work and a direct public link is refused. Operators set this up with `swarmfile-server admin federation peer add` and `admin federation repository allow`; see [Self-hosting](https://swarmfile.com/docs/guides/self-hosting#federating-public-repositories).

On a [protected repository](https://swarmfile.com/docs/admin/permissions#open-vs-protected-repositories), your **current** access governs what git can materialize: a teammate added to the repository can clone its whole history, including commits made before they joined - the derived ids depend on tree content, and the hub checks permissions as they are now. The hub separately remembers what access existed at each commit's time, which is what keeps point-in-time history views faithful; that replay isn't what git reads. If your access is revoked, git reads stop too, just like the file browser.

![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)

## Signing in

The helper looks for a credential in this order:

1. **`SWARMFILE_API_KEY`.** A repository API key in the environment wins over everything else, including a Desktop App session, and the helper says so when both are present.
2. **Your Desktop App sign-in.** On a machine where you're signed in to the Desktop App and no explicit key is set, `git clone` just works.
3. **A repository API key from git's credential store.** On a machine with no Desktop App session (a CI box, a container), store a repository API key (`sf_key_…`) as the password for the Swarmfile host with `git credential approve`, and the helper picks it up when no explicit key or session is present.

A key is repository-scoped, so for a **private** repository use its **id** in the URL - `swarmfile://<org>/<repository-id>`, or the host-qualified `swarmfile://<hub-host>/<org>/<repository-id>`. A repository key also cannot resolve a private org's **slug**, so use the org **id** for that segment in a CI URL (`swarmfile://<org-id>/<repository-id>`); the web Git access panel copies exactly that form. Resolving slugs needs a session; the refusal says which id to use. A stored credential (option 3) is never silently preferred over an explicit `SWARMFILE_API_KEY`.

A **branch-scoped** repository key can clone and push only its branch and needs the client's `SWARMFILE_BRANCH` pin (the helper does not infer it yet); a **path-scoped** key cannot use git at all (it is engine/API-only). A keyed clone still follows the access you hold today.

**Credentials stay with their authority.** A Desktop App sign-in is only used for the hub it was made against; a host-qualified URL that names another server is cloned anonymously (public repositories) or falls back to a credential stored for that host. An explicit `SWARMFILE_API_KEY` is global, so it is sent only to the configured hub unless you set `SWARMFILE_ALLOW_CROSS_HUB_KEY=1` - and with **no** configured hub, a host-qualified URL also requires that opt-in (the URL alone does not authorize the global key; both the standalone and engine helpers enforce this). Unset it before cloning a link to an authority you do not control.

On the hosted hub a **repository key cannot list the org's repositories** (by design), so resolving a renamed **repository slug** by name needs a signed-in session or the anonymous public clone; the helper also asks the hub's one-request `/public/<org>/_resolve/<repository>` route, so a public repository past the first directory page resolves. A repository **id** always works.

For a scripted sign-in, `SWARMFILE_OIDC_REFRESH_TOKEN` works and is **not** one-shot: the IdP rotates refresh tokens on use, but the live successor is persisted under the Swarmfile cache directory, and later commands - the push after a clone, a restarted engine, any other git command - reuse that stored successor instead of the spent environment value. Supplying a *different* token later still wins. A stored Desktop App session or a repository API key remains the simplest CI credential (no cache-dir file to carry between steps).

A clone needs to read the **whole** of every commit it fetches, and the hub checks permissions against the access you hold **today**. If a folder is restricted for you now, it can't hand those commits over complete, and a clone or fetch that has to walk one is refused with a message saying so rather than producing a repository with silent holes - grant read and the same clone succeeds, including commits made while you were restricted.

(The hub also records what access existed when each commit was made; that replay answers explicit point-in-time history views, not git.) The mounted drive and [`swarmfile materialize`](https://swarmfile.com/docs/cli/swarmfile#materialize) follow your access today in the same way. Use an owner's or a fully-permitted member's credential, or a repository API key, for clones of restricted content.

## What a clone contains

- **Branches and tags.** Every non-empty branch becomes a git branch; tags become git tags. A lightweight tag points at its commit; an annotated tag is re-emitted as the exact tag object that was pushed, so its message, tagger, signature and id survive. An empty repository clones as an empty repository.
- **Commits.** Each Swarmfile commit becomes a git commit, with your message and a `Swarmfile-Commit:` trailer naming the Swarmfile commit it came from. A commit with no message reads `(no message)`. Authors are recorded by account id; the helper writes a local mailmap so `git log` shows the names of people in your organization.
- **Unsaved-to-a-commit work.** If a branch has saves since its last commit (autosaves that haven't been rolled into one yet), the clone ends that branch with one extra commit, authored by `swarmfile` with the message "swarmfile snapshot of the live tree", so what you clone matches what's on the drive.
- **Large files as git-LFS pointers.** Files of 1 MiB or more come through as LFS pointers, with a generated `.gitattributes` in each folder that has them (added after any `.gitattributes` you already had). The clone is configured to fetch LFS content from Swarmfile automatically - see [Git-LFS](https://swarmfile.com/docs/guides/git-lfs) for the transfer agent and performance notes.
- **Symlinks** stay symlinks. A symlink's target must stay inside the repository; the drive and the UI validate it at the link's real depth. A `git push` create has no mount depth at upload time, so it uses the stricter rule and refuses an absolute target or one with a leading `..` (an internal `../` link the drive would accept at depth can be refused there; a moved link is checked at its destination depth, and a moved directory's descendants at the strict rule). **Empty folders** aren't carried (git can't store them). **Executable files** (marked with `chmod +x` on the macOS or Linux drive, or [`swarmfile chmod +x`](https://swarmfile.com/docs/cli/swarmfile#chmod)) arrive as mode `100755`; every other file is `100644`.
- **On Windows**, a path Windows can't create stops the clone with a message naming it.

Commit ids are stable: two people who clone the same repository get the same ids, and a later fetch never rewrites what you already have. A clone's `git log` shows git's own SHA-1, not this Swarmfile id; the web **Commits** page shows the reported git SHA-1 on a second line under the Swarmfile id (marked *unconfirmed* until a second principal's report confirms it).

## Staying up to date

Run `git fetch` (or `git pull`) in the clone. Only new commits are converted and downloaded, so a fetch after a day's work is quick. New branches and tags appear like they would from any remote.

If a branch is being saved to while you fetch, the fetch may ask you to retry shortly - it won't build a snapshot of a tree that's still moving.

**When a branch's newest commit can't be served yet.** A commit enters the git view once it has been *derived* (the Desktop App does this after each commit, or run `swarmfile git index`).

A provisional commit (derived but not yet confirmed) is served like any other to a signed-in clone - an anonymous clone serves confirmed history only, so a head that is still provisional is left out there with its reason until it confirms (normally within seconds of the push's claim on the hosted hub; a community server also confirms a member key's push, by rebuilding the tree from its own rows when the helper claims it (a claim the server cannot reproduce still waits for another key) - see [How a pushed commit gets confirmed](#how-a-pushed-commit-gets-confirmed)).

A head that has never been derived is derived and claimed on the spot when the credential running git may write - a signed-in app or a key heals the branch, and the command then works (any clone, fetch, push or `ls-remote` heals it; a clone with `swarmfile.confirm=false` has opted out).

When it can't (an anonymous or read-only clone, an opted-out clone, or a chain longer than the helper derives in one command), or when the claim is disputed, the branch is left out of the branch listing with that reason printed, rather than serving a stale pointer. Clones and fetches of the repository's other branches still work, and asking for that branch by name fails. The lasting fix for those is `swarmfile git index` from a machine with the Desktop App; it derives the selected drive's branch.

### A disputed claim

A disputed claim means two derivations of the same commit disagree. Swarmfile then derives the commit again on the server from its own records and keeps whichever claim matches, so a dispute usually resolves on its own within a minute or two and the branch serves again.

### Settling a rare dispute

The steps below are for the rare dispute where the server's derivation matches neither claim. Running `swarmfile git index` shows which hash your machine reproduces without submitting anything, and a repository owner or admin can read both recorded values with `swarmfile git disputes <commit number>` or in the **Commit disputes** section of the repository's Commits page on the web.

They then reset the commit with `swarmfile git clear-claim <commit number>` or the **Clear** button on that page, using the number the error names. The dispute record is kept after the clear.

Swarmfile then derives the commit again on its own (running `swarmfile git index` does the same, sooner), except when Swarmfile's own derivation was part of the dispute: then the commit waits for `swarmfile git index` from a member's machine.

Owners and admins are notified when a dispute is settled. A settlement that left the commit provisional can be overridden with the same clear; a settlement that confirmed the commit is final. Each settlement and each clear is recorded, with the values involved, in the **Recent changes** panel of the repository's Permissions page (with the whole repository selected).

## Pushing

`git push` sends commits from the clone back to the repository. Each git commit becomes one Swarmfile commit, and Swarmfile keeps the commit's exact author, committer, dates, message and any signature, so its id doesn't change: anyone who clones or fetches afterwards gets the same commit ids you have. Pushing works on managed, unencrypted and end-to-end-encrypted repositories - the latter through the desktop engine helper or the standalone/API-key helper with this device's user-key environment.

```bash
git push origin main                 # fast-forward an existing branch
git push origin my-feature           # a new branch is created on Swarmfile
git push origin :my-feature          # archive a branch
git push origin v1.0                 # a lightweight tag becomes a Swarmfile tag
git push -f origin v1.0              # move the tag to the commit you tagged
git push origin :refs/tags/v1.0      # delete the tag
git push -v origin main              # also print each commit's planned changes
git push --dry-run origin main       # run every check, write nothing
```

On a hub that predates the targeted protection read, `git push --dry-run` of a new branch reports its protection as **unknown**, not unprotected: the hub cannot evaluate a glob rule for a name with no branch row yet. The real push still applies the hub's refusal if a rule matches.

A successful push prints a link to the repository's commits in the web app (or to the merge request, below).

**What a push accepts:**

- **Fast-forwards only.** Your commits must build on the branch as Swarmfile has it, one first parent after another. A force push whose history shares no commit with Swarmfile - a rewritten root - is refused, and a helper-created clone translates an ordinary force push (a rebase plus force included) into a forward commit by default (see below); an older clone can opt into that translation with `swarmfile.force-forward`. A `git merge` of the remote into a diverged local branch is also refused - a merge commit must sit *on top of* the remote head, so fetch and `git pull --rebase` instead. If someone saved to the branch since you last fetched, git reports `fetch first`: run `git pull --rebase`, then push again. Saves on the drive that haven't been rolled into a commit count too, since a fetch turns them into a snapshot commit. If you need the branch's *tree* to be yours anyway, without rewriting history, run [`swarmfile git force-forward`](https://swarmfile.com/docs/cli/swarmfile#git-force-forward) in the clone: it pushes a forward commit whose tree is your tip's (your commits keep riding the auto-archived `merged/<sha>` side branch, so nothing is lost and teammates fast-forward) and prints the `git fetch <remote> && git reset --hard <remote>/<branch>` that re-aligns your clone. A rewritten **root** commit (an amended initial commit) cannot land this way - the replaced history shares no commit with Swarmfile, so the push refuses naming the unrelated root; push that as a new branch instead.
- **New branches.** Pushing a branch Swarmfile doesn't have creates it, starting from the newest commit in your history that Swarmfile already holds.
- **Merge commits** with two parents. If the history you merged isn't on Swarmfile yet, the push sends it first, to a branch named `merged/<first 12 characters of its newest commit>` that starts where that history left the main line (an existing one is reused). The push lists each branch it creates. Once the merge itself lands, the push archives the branch; its commits stay reachable through the merge, so the history doesn't change. If those commits aren't confirmed yet (below), the branch stays until a teammate's fetch has confirmed them, and your next fetch or push archives it then. A `merged/*` branch someone has added commits to is left alone. This works for merges nested inside merged history too. History that shares no commit with the repository at all (a merge of an unrelated repository) is refused, naming the commit. An octopus merge (three or more parents) is accepted when every parent after the second is already on Swarmfile - push those branches first; an extra parent that isn't on the hub is refused with that instruction.
- **Protected branches** don't move. Your commits go to a branch named `push/<branch>/<first 12 characters of your commit>`, started at the protected branch's head, and the push opens a merge request into the protected branch, or reuses the one already open from that branch (also when another push opened it a moment earlier: the push links that merge request instead of failing). Git reports the ref as not updated, with `opened merge request #<n> (push/<branch>/<commit>)`; the link takes you to it. The same rules apply to `merged/*` branches: if one is protected, the push is refused.
- **Root creates need root authority.** On a protected repository, a commit that adds a new name directly at the repository root - or moves one there - is refused unless you're an org owner, the repository's creator, or hold a repository-wide `write` (or higher) grant; a folder-scoped grant doesn't qualify, and overwriting an existing root file doesn't need it. The push names the remedy: move the files inside a folder and push again, or ask an owner for repository-wide write access. See [Permissions](https://swarmfile.com/docs/admin/permissions#open-vs-protected-repositories).
- **Deleting a branch** (`git push origin :<branch>`) archives it, and it can be restored from the web app. `main` and protected branches can't be deleted this way.
- **Tags.** A lightweight or annotated tag on a commit Swarmfile holds becomes a Swarmfile tag on that commit; an annotated tag's object is stored and re-emitted verbatim, so `git tag -a` and `git tag -s` keep their message, tagger, signature and id. To move an existing tag, retag and push with `--force` (`git push -f origin <tag>`); the commit must already be on Swarmfile, and replacing an annotated tag with a different object or a lightweight tag also needs `--force`. `git push origin :refs/tags/<tag>` deletes a tag. A tag that a [release](https://swarmfile.com/docs/guides/publishing-releases) was published from can be neither moved nor deleted.
- **Large commits.** A commit that changes more than 5,000 paths is sent in parts and applied as one commit, up to 2,000,000 paths. The branch is locked while it applies. Above 100,000 paths Swarmfile applies the commit in stages after the upload, and the push shows its progress. Anyone reading the branch during that time can see the files that have been applied so far. If the push is interrupted after the parts were sent, push again: it picks up where it left off. If someone else's change gets onto the branch while a staged commit is applying, Swarmfile stops the commit. The push then reports how far it got, and the changes already applied stay on the branch as uncommitted changes for you to review. To undo them, use **Roll back** on the notice the web app's Commits page shows for that branch: every file the push touched goes back to how it was before the push, as one new commit you can revert. The person who pushed and repository owners can roll back, and the rollback is refused if any of those files has changed again since the push stopped.
- **A commit already on another branch** (for example a fast-forward of `main` to your feature branch's tip) is recorded again on the target branch with the same commit id, so both branches show the same history.

**If your history diverged.** Two shapes are the same problem: the branch moved while you worked, and a `git merge` of the remote into your line cannot be pushed - a push must continue the remote head along its first parents:

```text
        A---B---C        the branch on Swarmfile (C is the head)
             \
              X---M      your clone: X, then M = merge(X, C)     <- refused
```

`git pull --rebase` is the supported way back: your work replays on top of `C` as `A---B---C---X'`. When you need your merged *tree* as it stands, [`swarmfile git force-forward`](https://swarmfile.com/docs/cli/swarmfile#git-force-forward) lands it as a new commit `F` on top of `C` instead - nothing is rewritten, `C` and `X` stay reachable, and everyone else fast-forwards:

```text
        A---B---C---------------F     F's tree = M's tree
             \                 /
              X-------------M
```

A clone created through the helper also makes plain `git push --force` (and `--force-with-lease`) take the same path by default (`swarmfile.force-forward=true`); an older clone can opt in with `git config swarmfile.force-forward true`, or set it false to keep the refusal. Because git's own bookkeeping then points your remote-tracking ref at the tip you sent rather than the commit that landed, follow the note the helper prints - `git fetch`, then reset your branch to the fetched one - before pushing again.

**Push an existing repo into a new repository.** A repository that has never been on Swarmfile goes into a repository where the branch you're pushing to (`main` in this example) has no commits and no files yet, with its whole history:

```bash
git remote add origin swarmfile://<org>/<repository>
git fetch origin                     # configures git-LFS (and its credential) for Swarmfile
git lfs push --all origin main       # if the repository uses git-LFS
git push origin main
```

The first commit lands with no parent, merges bring their merged history along as described above, and a fresh clone afterwards has the same commit ids. The push sends consecutive commits together, up to 100 commits or 5,000 changed paths per request, within the plan's request budget. Uploading file content and indexing each commit take most of the time. When the budget does run out, the push waits for it and carries on. A `main` that already has files but no commit can't take a root commit: fetch first, and the push builds on the snapshot.

**What a pushed commit may contain.** Swarmfile accepts a commit only if it is exactly what a clone of the result would produce, so `git fetch` never rewrites it. The push checks every commit, and asks the hub to check the first one, before uploading anything, and names the file and the fix when one doesn't fit:

- **Submodules.** A gitlink (mode `160000`) is pushed and cloned with its exact target commit id; the mount hides the submodule path (it has no bytes in this repository) and recursive submodule clones are not rewritten (the submodule URL is external). An executable file (`100755`) is fine: it lands as an executable Swarmfile file, and a commit that only flips the bit (`git update-index --chmod=+x|-x <file>`) is a change like any other.
- **Large files must be LFS pointers.** A file of 1 MiB or more (the repository's frozen threshold) must be committed as a git-LFS pointer, and its content must already be on Swarmfile. The clone is configured to send LFS content to Swarmfile with the same credential the clone uses (your signed-in Desktop App session, a stored `sf_key_` key, or `SWARMFILE_API_KEY`; nothing to set up), so git-LFS's own pre-push step normally takes care of that; if a push says an LFS object is missing, run `git lfs push origin <branch>` and push again. A file under the threshold must be committed as a regular file, not as a pointer.
- **Each LFS file is covered in its folder's `.gitattributes`**, either by a `git lfs track` pattern in that folder's own `.gitattributes` (for example `*.psd filter=lfs diff=lfs merge=lfs -text`), or by the line a clone writes for a file the patterns don't cover: `/<name> filter=lfs diff=lfs merge=lfs -text`, one per file, sorted by name, at the end of the file after the line `# swarmfile: generated LFS attributes - view v1`. Only patterns in the file's own folder count, not ones in parent folders, and a pattern with a `/` in it covers nothing. That matters for `git lfs track`: run at the repository root as `git lfs track "media/*.psd"`, it writes a pattern with a `/` into the root `.gitattributes`, which covers nothing here. Put the pattern in the folder's own file instead, for example `printf '*.psd filter=lfs diff=lfs merge=lfs -text\n' >> media/.gitattributes`. A `lockable` attribute on the line (what `git lfs track --lockable` adds) is fine. When a folder's lines don't match, the push prints the lines it expects.

What happens to the files on the drive:

- Changed, new and deleted files become the same changes on the drive. A file renamed without changes keeps its Swarmfile history, and so does a whole folder renamed or moved without changes: it moves as one folder.
- Folders you add are created, and folders your commit empties are removed. Empty folders that exist only on the drive (git can't show them) are left alone.
- A push of several commits sends them in batches, and each commit is applied as a separate Swarmfile commit, in order. If one is refused, the commits before it have already landed, and the branch stays at the last of them. Fix the refused commit and push again to continue from there.
- Commits you push are *provisional* until a second, independent derivation confirms them. Swarmfile's hosted hub queues its own confirming derivation the moment the push's claim lands, so a pushed commit normally confirms within seconds; a community server confirms a member key's push from its own tree derivation at claim time (a claim it cannot reproduce waits for another key's claim, and on a community server an **owner key's own first claim** self-attests directly - there is no self-confirmation setting there; a teammate's fetch also confirms). On the hosted hub, a repository owner with self-confirmation turned on likewise confirms their own first claim. A push whose helper died before claiming is caught by a couple-of-minutes backstop, which derives the commit but still needs a client's matching derivation to confirm it. Provisional commits are cloned and fetched like any other. While one is provisional, its row on the repository's **Commits** page shows no commit hash - hovering the dash explains why - and the hash appears on the page's next refresh once confirmation lands (the page keeps re-checking for a couple of minutes after a push).

### How a pushed commit gets confirmed

A commit is confirmed when a second person works out its file tree independently and gets the same result as the person who made it. You don't have to do anything for that to happen:

- **Swarmfile's server confirms what a signed-in app already claimed.** As soon as a `git push`'s claim (or a snapshot mint by the Desktop App) lands, the hub queues its own derivation and confirms the commit when the result matches - no teammate's fetch needed. A commit no app ever claimed (a web upload, a revert, a merge) is derived by the server but still needs a client's matching derivation (the routes below) to confirm.
- **A teammate's `git fetch` or `git clone` confirms what it brings in.** After the fetch, the helper recomputes each new provisional commit that someone else made, from the branch's history as of that commit, without reusing their results, and sends the result to Swarmfile. Parents go before their children, so a whole chain of commits is confirmed in one fetch. One fetch confirms up to 200 commits, oldest first, and the next fetch continues. A fetch never confirms your own commits, a shallow clone only confirms the commits it fetched, and if confirming fails (for example because of a rate limit), the fetch still succeeds and the next one tries again.
- **`swarmfile git index` confirms a whole branch at once** on a machine with the Desktop App. With no argument, it confirms the branch head and every unconfirmed commit behind it, oldest first, back to the nearest commit that is already confirmed (or one you made yourself). It handles up to 1,000 commits in one run and lists what happened to each commit. `swarmfile git index <seq>` handles just that one commit.

If the two results don't match, the commit can't be confirmed. Swarmfile records both results for the repository owner to review. A fetch prints a warning and still succeeds. `swarmfile git index` names the commit and exits with code `2`. Commits that come after it in the same run aren't confirmed.

To keep a clone from confirming commits (a read-only mirror, say), turn it off in that clone:

```bash
git config swarmfile.confirm false
```

or clone with `git clone -c swarmfile.confirm=false swarmfile://<org>/<repository>`.

The same setting also turns off the on-demand derivation of a branch head that has never been derived: a git command in that clone then leaves the branch out of the listing with the `swarmfile git index` guidance instead of claiming it.

## When a clone fails

The helper always says why: its message prints above git's `fatal: remote helper 'swarmfile' aborted session` line, and the same text is written to `git-remote-last-error.log` in the Swarmfile cache directory (`~/.cache/swarmfile` on macOS and Linux, `%LOCALAPPDATA%\Swarmfile` on Windows) - include it if you contact support.

The common causes: git access isn't turned on for the repository ([Turning on git access](#turning-on-git-access)); the repository is private and the signed-in account isn't a member of its organization (a **public** repository with anonymous cloning on doesn't fail this way - a credential the hub refuses is named in a one-line notice and the clone continues anonymously, see below); or the repository name in the URL doesn't resolve (use `swarmfile git url <repository>` to print a URL that does).

## If a clone gets into a bad state

A clone is a local, derived view: every commit id is recomputed from the repository's branch state, so a clone you have wrecked - bad refs, a half-finished rewrite, a corrupted object store - can always be replaced. Only work that exists nowhere else is worth rescuing first.

- **Save unpushed work**: `git bundle create rescue.bundle --all` (one file you can move anywhere), or `git format-patch origin/<branch>..HEAD -o ../patches`. To land it on Swarmfile instead, push it to a throwaway branch - `git push origin HEAD:rescue/<name>` creates a new branch forked at the newest commit Swarmfile already holds.
- **Re-clone**: `rm -rf <clone> && git clone swarmfile://<org>/<repository>` gives a pristine view with identical commit ids. Generated clone config (git-LFS wiring, `swarmfile.confirm`) is recreated.
- **Repair in place**: `git fetch origin --prune`, then `git checkout -B <branch> origin/<branch>` (or `git reset --hard origin/<branch>`) and `git clean -fdx`; `git fetch --unshallow` if the clone is shallow; `git replace -d <ref>` followed by `git reflog expire --expire=now --all && git gc --prune=now` drops local rewrites.

If a bad state reached Swarmfile itself (junk branches, a moved tag, a bad commit), a local reset won't undo it: archive the junk branch (`git push origin :<branch>`, restorable from the web app), push the tag back (`git push -f origin <tag>`, unless a release used it), commit a revert forward, or ask an owner to clear a stuck commit claim with `swarmfile git clear-claim <seq>`.

## Limits and caveats

| | |
|---|---|
| **An octopus merge whose extra parents are not on Swarmfile** | Push the side branches first, then the merge. A merge of three or more branches whose parents are all on the hub pushes and clones with its exact parent order. |
| **A force push with a rewritten root** | A helper-created clone translates an ordinary force push (a rebase plus force included) into a forward commit by default; a force push whose history shares no commit with Swarmfile (a rewritten root) is refused, and an older clone refuses force pushes until `swarmfile.force-forward` is enabled. Swarmfile history is append-only; push new commits instead. To land a force push's end state - the branch's tree is yours - as a forward commit, run `swarmfile git force-forward` in the clone, or set `git config swarmfile.force-forward true` on an older clone (set it false to keep the refusal) so ordinary force pushes are translated (see [Pushing](#pushing)). Tags can be moved with `--force` and deleted, unless a release was published from them. See [Pushing](#pushing) for what a push accepts. |
| **Pushing to an end-to-end-encrypted repository** | Supported by the desktop engine helper and by the standalone/API-key helper with this device's user-key environment (the view is all-inline; LFS stays refused). |
| **Shallow clones** | `--depth`, `--deepen` and `--unshallow` work once the commits at the cut have been indexed (`swarmfile git index`). A depth fetch also needs those boundary commit ids *confirmed*; on a repository only one person derives, set [`SWARMFILE_GIT_ACCEPT_PROVISIONAL=1`](https://swarmfile.com/docs/reference/environment-variables) where you run the clone (or let a second person confirm them: a teammate's fetch, or `swarmfile git index` - see [How a pushed commit gets confirmed](#how-a-pushed-commit-gets-confirmed)). `--shallow-since` and `--shallow-exclude` aren't supported. |
| **Partial clones** | `--filter` is not supported through the `swarmfile://` helper; large files already arrive as LFS pointers. The read-only HTTPS gateway supports `--filter=blob:none` for public plaintext repositories. |
| **Anonymous clones** | Read-only, and **on by default** for a public, git-enabled repository. An owner can turn it off from **Repository settings → Public page** (web and desktop), or `swarmfile git anonymous-clone off`. While on, a signed-out visitor can clone, fetch, `git lfs pull`, and read - but never push. Anonymous clone is unavailable while any active branch's committed tree carries a `.swarmfile/publicignore.yml` that hides a path in it, any tag's committed tree carries one that hides a path, or a ready (published) release hid paths; an already-published older release keeps the contents it was built with. The check reads both committed trees a branch can advertise (its confirmed head changeset tree and its live head tree - they differ for a fork taken from a dirty source) and every tag's committed changeset tree. An invalid or unreadable policy, or a boundary read/walk error, refuses anonymous clone (fail closed). There is no filtered clone, because hiding paths at the same commit ids would contradict the public history (a change takes effect within about a minute; a path that exists only in an older commit is not retroactively hidden). A clone also contains the commit and annotated-tag messages and the committed `.swarmfile/publicignore.yml` itself verbatim - filtering either would change commit ids - so never put a secret in a public commit message. The web commit list and the federation activity/commit feeds redact path names the policy hides; a git clone does not. The boundary is anonymous-only - member clones are governed by the ACLs described above, so a restricted folder can still refuse one. Publishing a release that would hide paths requires anonymous cloning off; once the release is ready, turning it back on does not re-expose the paths while the ready release or an active branch's committed tree still hides them. A signed-in account the hub refuses for the repository (not a member of its organization, a revoked or expired key, or a key scoped elsewhere) gets the same anonymous read: the helper prints one line naming why (the refusal, or the lookup failure for a repository the account can't see yet), then continues read-only. |
| **Fetching a commit by id** | Only branches and tags can be fetched, not an arbitrary commit id. |
| **A stock `https://…` git URL** | The hosted hub does not serve one. An operator can run the read-only `swarmfile-git-gateway` (public plaintext repositories; stock clone/fetch including `--filter` and sparse checkout, a download-only LFS proxy, no upload/lock/push, TLS at a reverse proxy) and clone `https://<gateway>/<org>/<repository>.git`; otherwise clone through the `swarmfile://` helper (which connects to a host-qualified hub over HTTPS, or HTTP for loopback/an allowlisted host). |
| **End-to-end-encrypted repositories** | Supported by the desktop engine helper and by the standalone/API-key helper with this device's user-key environment (the view is all-inline; LFS stays refused). |
| **Branch or tag names git can't represent** | Refused with a message naming them. |

Two kinds of problem tell you how to fix them: a large file that has no recorded id (enable records missing ids automatically, or run `swarmfile git backfill-oids` yourself), and a clone made against a different git view version must be re-cloned (the helper says so).

## See also

- [Clone and push a Swarmfile repository with git](https://swarmfile.com/blog/clone-and-push-a-swarmfile-repository-with-git) - the announcement post, with the end-to-end walkthrough.
- [Git and Swarmfile](https://swarmfile.com/docs/guides/git-and-swarmfile) - every way git and Swarmfile meet, side by side.
- [Coming from Git](https://swarmfile.com/docs/guides/coming-from-git) - the command cheat sheet for day-to-day work on the drive.
- [Runner (Headless CI)](https://swarmfile.com/docs/guides/runner-as-ci) - CI that runs on a Swarmfile branch without a clone at all.
