---
title: Mirrors
description: Publish a filtered copy of part of your repository to another git
  repository, such as a public SDK repo.
group: reference
lastModified: "2026-11-29T23:55:49Z"
lastAuthor: Christopher Burns
---
# Mirrors

A mirror runs the other way from a vendored package. Your repository is the source of truth, and `inrepo mirror` publishes a filtered copy of one of its directories to another git repository. Use it to keep an SDK, tests and internal files together in a private monorepo while a public repository receives only the files you choose to publish.

Declare mirrors in `inrepo.json` (or `package.json#inrepo`):

```json
{
  "packages": [],
  "mirrors": [
    {
      "name": "sdk",
      "git": "https://github.com/acme/sdk.git",
      "branch": "main",
      "directory": "packages/sdk",
      "exclude": [
        "/\\.(test|spec)\\.[cm]?[jt]sx?$/",
        "/(^|/)(__tests__|__snapshots__)$/",
        "internal"
      ]
    }
  ]
}
```

|Field|Meaning|
|--|--|
|`name`|Label used on the command line. Required, unique, and without `:` or line breaks.|
|`git`|Target repository URL or path (not a git remote name). Required.|
|`branch`|Target branch. Defaults to `main`.|
|`directory`|Directory in this repository, relative to the config, that becomes the target's root. Defaults to the config directory.|
|`keep`|Path prefixes under `directory` to publish. When set, it must list at least one path, and nothing else is published.|
|`exclude`|Paths or `/regex/` patterns under `directory` that are never published. A literal drops a file or a whole directory. A regex drops any file whose path, or any parent directory's path, matches.|

`keep` and `exclude` follow the same rules as they do for vendored packages: `keep` runs first, then `exclude`. Root-level `keep` and `exclude` apply only to vendored packages, not to mirrors.

## Publishing

```bash
npx inrepo mirror --dry-run   # list what would change on each mirror, push nothing
npx inrepo mirror sdk         # publish one mirror
npx inrepo mirror             # publish every mirror
```

Each run reads the committed tree at `HEAD` (or `--ref <rev>`), never your working tree or index, so uncommitted files are never published. The mirror config must match that commit too: the run stops unless the config on disk declares exactly the same mirror as the one committed at that revision (in `inrepo.json`, or `package.json#inrepo` when the commit has no `inrepo.json`). Uncommitted config edits, a deleted `inrepo.json`, and `--ref` to a commit with different filters all stop it. It builds one commit whose tree is exactly the filtered directory, on top of the target branch's current tip, and pushes it. Files you delete or exclude in the source are deleted on the target. If the target already has exactly that content, nothing is pushed. `-m "<subject>"` sets the commit subject; the default is `Mirror <short sha>`.

Every mirror commit ends with three trailers: `Inrepo-Mirror-Source: <sha>`, the source commit it was built from, `Inrepo-Mirror-Tree: <sha>`, the tree inrepo wrote, and `Inrepo-Mirror-Name: <name>@<hash>`, the mirror that wrote it, where the hash identifies the config's directory without naming it. The commit message contains nothing else from your repository, so private commit messages stay private.

The target's root becomes exactly `directory`. Anything else on the target, such as a `LICENSE` or `.github/` folder that only exists there, is deleted by the first run, so keep those files inside `directory` in your repository.

With `--json`, the command prints one result envelope with each mirror's `action`, commit and file changes, and failures carry a stable `error.code` such as `MIRROR_TARGET_CHANGED`. See the [command reference](/docs/commands) for the shape.

Submodules and paths that are not valid UTF-8 are refused rather than published; exclude them. A run that would publish no files at all stops instead of emptying the target, since that usually means a wrong `directory` or filter; to retire a mirror, delete its branch on the target.

## Running it in CI

Run mirrors from CI on your protected branch, after changes are merged. Publishing from a local feature branch publishes unmerged code, and once that branch is squash-merged, the next run from the main branch looks like a rollback.

* **History:** the rollback check needs the previous source commit locally, so check out full history (for example, `actions/checkout` with `fetch-depth: 0`). Partial clones (`--filter=blob:none`) are not supported: inrepo cannot download missing file contents, so the run fails before anything is pushed.
* **Identity:** the mirror commit's author and committer come from `GIT_AUTHOR_NAME`/`GIT_AUTHOR_EMAIL` (and the `GIT_COMMITTER_*` pair) when set, otherwise from `user.name` and `user.email`. They are public on the target, so set a bot identity in CI. If none is configured, the run fails instead of guessing one from the machine.
* **Credentials:** inrepo builds the commit in a temporary repository, so repository-local git config such as `http.extraheader` does not apply to the push. Use a credential helper or `url.<base>.insteadOf` in global config, an SSH key, or the `GIT_CONFIG_COUNT`/`GIT_CONFIG_KEY_<n>`/`GIT_CONFIG_VALUE_<n>` environment variables. inrepo hides `user:token@` parts of URLs in its output, and git never prompts for a password. The `git` value is used as written: it is a URL or path, not a remote name, and a relative path is resolved against the config directory.
* **Ordering:** a run that finds the target already holding its content pushes nothing, so the target keeps recording the last commit that changed it. A late run for an older commit could therefore publish older content. Run mirror jobs one at a time (for example, a GitHub Actions `concurrency` group with `cancel-in-progress: false`), and have each job check out and mirror the latest commit of the protected branch, not the commit that triggered it (for example, `actions/checkout` with `ref: main`), so a job that runs late still publishes the newest content.
* **Workflow files:** on GitHub, pushing changes under `.github/workflows/` needs a token with the `workflow` scope.

## Safety checks

`inrepo mirror` never rewrites history on the target, and it stops instead of silently replacing work:

* If the target tip is not an unmodified mirror commit, someone committed to the target directly, edited or amended a mirror commit, or this is the first mirror run. Port any changes made there into your repository, then rerun with `--overwrite`. The run still adds a commit on top.
* If the target branch was last written by a different mirror, the run stops: two mirrors cannot share a branch. After renaming a mirror or moving its config, pass `--overwrite` on the next run that changes content (a run with nothing to change pushes nothing, so it records no new name).
* If the target was last mirrored from a commit that is not an ancestor of the one you are publishing, publishing would roll it back, so the run stops. `--overwrite` publishes anyway.
* If the target branch moves between the moment inrepo reads it and the push, the push is rejected. Rerun to publish on top of the new tip.
