# Add --exclude-ref-prefix to trim namespaces from --all-refs

`ee37983`→[main](/content/gh/entireio/git-sync/commits/main/index.html)·

Soph·2mo ago·16 files·+256 added/-54 removed

GitHub's refs/pull/* namespace is the load-bearing case: every PR ever opened against an open-source repo contributes a refs/pull/N/head that points at a commit in someone's fork. --all-refs against a busy repo (kubernetes ~120k PRs, react ~17k PRs) drags all of those into the target, even when the fork is long gone.

--exclude-ref-prefix subtracts namespaces from auto-discovery and prune scope. Excluded refs are left alone entirely: not pulled from source, not pushed to target, not pruned from target. Explicit --map values override the filter, since they're explicit user intent.

Common shape:

```bash
git-sync sync --all-refs --exclude-ref-prefix refs/pull/ <src> <tgt>
```

The flag is repeatable across all sync-like commands plus probe and fetch. ExcludeRefPrefixes is also exposed on RefScope (and on ProbeRequest for probe-only callers) at the library level.

Implementation: a small IsRefExcluded helper in planner gates four sites — the branch walk, the tag/other walk, addPruneCandidates, and replicateCanBootstrap's prune-shortcut check. The wildcard filter applies in BuildDesiredRefs' three auto-discovery paths; the Mappings path bypasses it by construction. Wire-level ls-refs still requests "refs/" under AllRefs (the wire protocol's prefix arg is include-only), and the filter applies client-side.

Tests:
- planner unit: ExcludeRefPrefixes subtracts under AllRefs, doesn't override explicit Mappings.
- integration: sync seeds refs/pull/1/head + refs/notes/commits, then syncs with --all-refs --exclude-ref-prefix refs/pull/ and asserts notes lands but pull doesn't.
- CLI smoke: cobra entry through the full pipeline.

Docs: usage.md walks through the GitHub use case and the subtract-from-auto-discovery semantics.

## Sessions

## Changes

16

- Mclient.go+5/-3

- cmd/git-sync

- Mbootstrap.go+1
  - Mfetch.go+1
  - Mflags.go+9
  - Mmain_test.go+41
  - Mprobe.go+1
  - Msyncplan.go+1

- docs

- Musage.md+17

- internal

- planner

- Mplanner.go+13
    - Mplanner_test.go+35
    - Mtypes.go+20

- syncer

- Mintegration_test.go+43
    - Msyncer.go+11/-6

- internalbridge

- Mconfig.go+13/-10

- Mtypes.go+15/-10

- unstable

- Mclient.go+30/-25

## CLI usage

You can use the command like this:
```bash
git-sync sync \
  --all-refs \
  --exclude-ref-prefix refs/pull/ \
<source-url> \
<target-url>
```

Additionally, `--exclude-ref-prefix` subtracts from auto-discovery (branches, tags, and `--all-refs` namespaces) and from prune scope, so excluded refs are left alone entirely: not pulled from source, not pushed to target, not pruned from target.
