skills/sync-fork/SKILL.md
Sync a forked repository with its upstream. Fetches both remotes, shows divergence, resets shared branches to upstream, re-merges local-only branches, cleans up branches already merged upstream, and pushes. Use when upstream has accepted PRs or moved ahead and you need to bring your fork in line.
npx skillsauth add shhac/skills sync-forkInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Sync a forked repository with its upstream remote. The fork's shared branches (e.g., main) are maintained as the equivalent of upstream plus local patches re-merged on top — a "patched upstream" model. Each sync resets to upstream, rebases fork-only branches, and re-merges them.
If upstream hasn't advanced (i.e., upstream/main is already an ancestor of fork/main), the sync is a no-op.
/sync-fork [<fork-remote> <upstream-remote>]
git remote get-url <name> and ask the user: "<name> points to <url> — is this your fork, or the repo you forked from?" Then ask for the other remote name.When auto-detecting with exactly two remotes, use heuristics to guess which is the fork and which is upstream (e.g., a remote named origin is more likely the fork; a remote whose URL org differs from the other is more likely upstream). Present your guess and ask the user to confirm.
⚠️ Credential safety: Remote URLs may contain embedded credentials (e.g., https://user:[email protected]/...). Before displaying any URL to the user, redact the userinfo portion: replace user:token@ with ***@. Never output raw credentials from git remote -v or git remote get-url.
Used in reference files adjacent to this skill:
─── flow (left-to-right = time)
├── X branch X forks here
└── X branch X forks here (last branch at this point)
──┘ merge point (branch merges into line above)
● notable state on the line
This skill includes scripts/sync_fork.py — a deterministic Python helper for branch analysis. It handles classification, divergence checking, and dependency graph building so these operations produce consistent results. Requires Python 3.9+ (stdlib only).
Locate the script relative to this skill file. Invoke it as:
python3 <skill-dir>/scripts/sync_fork.py <subcommand> [options]
Subcommands: classify, divergence, graph, plan. Run with --help for full usage. Default output is compact key-value (LLM-friendly). Add --json for structured output.
You are syncing a fork with its upstream. Follow the phases below in order.
This skill uses incremental discovery — the main flow below covers the common case. When you encounter a specific situation (a topology, an edge case), you will be directed to read the relevant reference file at that point. Do not read all reference files upfront. Read them only when triggered.
Reference files live in two directories adjacent to this skill:
examples/ — branch topology diagrams and rebase strategiesedge-cases/ — handling for unusual situationsCheck for interrupted previous run. Look for branches matching sync-fork/*. If found, a previous sync was interrupted. Show the user what backup branches exist and ask: restore from backups, or clean up (git for-each-ref --format='%(refname:short)' 'refs/heads/sync-fork/' | xargs git branch -D) and start fresh?
Save current branch. Record git symbolic-ref --short HEAD (or the detached commit) so we can restore it at the end.
Guard dirty working tree. Run git status --porcelain. If there are uncommitted changes, stash them:
git stash push -m "sync-fork: uncommitted changes"
This will be popped at the end. Stash is branch-independent, so it survives the checkout/reset operations that follow.
Identify remotes. Run git remote -v and resolve which remote is the fork and which is upstream using the rules in the Usage section above. Confirm with the user if there was any ambiguity.
Fetch both remotes.
No-op check. For each shared branch, check git merge-base --is-ancestor <upstream>/<branch> <fork>/<branch>. If upstream is already an ancestor of fork for ALL shared branches, the sync is a no-op — upstream hasn't advanced. Tell the user and stop.
Classify branches. Run the helper script:
python3 <script> --fork <fork> --upstream <upstream> classify
This identifies shared branches, fork-only branches (merged, promoted, partially promoted, active), and reports them in a compact format.
fork-only-partial entries appear → read edge-cases/partial-promotion.md.fork-only-promoted entries appear → read examples/promoted-branch.md for the full handling strategy.Check divergence. Run the helper script:
python3 <script> --fork <fork> --upstream <upstream> divergence
This shows per-branch commit counts and flags.
rewrite=true AND fork_merges_only=false → STOP and read edge-cases/history-rewrite.md before proceeding. This may be a real upstream rewrite, or it may be expected patched-upstream divergence where fork-only branch commits are already merged into the fork's shared branch.reverts>0 → STOP and read edge-cases/upstream-reverts.md before proceeding.Dry-run plan. Run:
python3 <script> --fork <fork> --upstream <upstream> plan
Present the full plan to the user. Wait for confirmation before proceeding.
Create all backups upfront (both pre-reset and pre-rebase) before any destructive operations. This consolidates recovery points into a single step.
# Pre-reset backups for shared branches
for branch in <shared_branches>; do
git branch sync-fork/pre-reset/$branch <fork>/$branch
done
# Pre-rebase backups for fork-only active branches
for branch in <fork_only_active>; do
git branch sync-fork/pre-rebase/$branch <fork>/$branch
done
These backups serve triple duty:
--onto rebases (the sync-fork/pre-rebase/<parent> tip IS the old ref)For each shared branch (in order: default branch first, then others):
git checkout will auto-create one.)git reset --hard <upstream>/<branch> to align with upstream.git push <fork> <branch> --force-with-lease to update the fork.Run the helper script to build the dependency graph. It uses the sync-fork/pre-reset/* backup refs for shared branch ancestry checks (since shared branches now point to upstream):
python3 <script> --fork <fork> --upstream <upstream> graph \
--branches <comma-separated-fork-only-active> \
--shared <comma-separated-shared> \
--backup-prefix sync-fork/pre-reset
The output provides: parent map, topological order, orphaned branches, and merge targets.
orphaned is not (none) → read edge-cases/orphaned-branches.md.parent but does have a target, it is already contained in the pre-reset shared branch. Treat it as an independent branch targeting that shared branch, not as an orphan.You MUST read the applicable example file before continuing. Match the dependency graph you just built to the correct topology and read that file now:
| Topology detected | Read this file |
|---|---|
| All branches root directly on a shared branch, no dependencies between them | examples/independent-branches.md |
| One branch depends on another (B based on A) | examples/linear-chain.md |
| Multiple branches depend on the same parent (B and C both based on A) | examples/fan-out.md |
| Three or more branches in a chain (A → B → C) | examples/deep-chain.md |
| Branches root on different shared branches | examples/multi-target.md |
| Mixed (combination of above) | Read ALL applicable files |
If the graph has any dependencies between fork-only branches, you must understand the --onto rebase strategy from the relevant file before proceeding. Getting this wrong causes duplicate commits and false conflicts.
For each fork-only branch (parents first, children last — use the order from the graph output):
Check for merge commits: git log --merges sync-fork/pre-rebase/<parent>..<branch>
edge-cases/merge-commits-in-branches.md before rebasing this branch.Rebase:
git rebase --empty=drop <shared-branch> <branch>git rebase --empty=drop --onto <parent> sync-fork/pre-rebase/<parent> <branch>target=<shared-branch>: git rebase --empty=drop <shared-branch> <branch>--empty=drop automatically discards commits already in upstream. If Git < 2.26, omit the flag and use git rebase --skip when prompted.Check for empty result. If ALL commits were dropped (branch now points to same commit as its parent), warn the user: "Branch <branch> appears fully absorbed by upstream. Consider deleting it."
git push <fork> <branch> --force-with-lease to update the fork.
The fork's shared branches are maintained as "upstream + local patches." This phase replays merge commits on top, so fork/main = upstream/main + fork-only work.
For each shared branch that has fork-only branches targeting it (use the target map from the graph output):
--no-ff in topological order (parents before children). Use the message format:
git merge --no-ff <branch> -m "sync-fork: merge <branch> into <shared-branch>"
git push <fork> <branch> --force-with-lease to update the fork.git push <fork> --delete <branch>) that are fully merged into upstream.git range-diff <old-base>..sync-fork/pre-reset/<branch> <upstream>/<branch>..<branch> before deleting backups.git for-each-ref --format='%(refname:short)' 'refs/heads/sync-fork/' | xargs git branch -Dgit checkout <saved-branch>.git stash pop.--force-with-lease, never --force, when pushing reset branches.sync-fork/ prefix — these are temporary and cleaned up at the end. If a sync is interrupted, they survive for recovery. Clean up manually with git for-each-ref --format='%(refname:short)' 'refs/heads/sync-fork/' | xargs git branch -D.development
Review a GitHub pull request using the passive, neutral, assertive, or aggressive profile, optionally paired with a named reviewer persona that sets the review voice, by statically reading the PR diff, metadata, comments, and discovered issue/context links to determine whether it solves the stated issue. Use for automated or manual PR review flows that should leave an emoji-marked top-level review plus targeted inline comments or suggestion blocks, without running code or blocking except for malicious-looking changes.
development
Audit a codebase's module boundaries — enumerate modules, map their seams (import edges between modules), produce a layered topology diagram, and classify each module as narrow, hub-by-design, or accidental hub (with separate flags for cycles, layer violations, and uncertain import graphs). Outputs a diagram plus a flagged-for-review list; does not change code. Use when assessing whether abstractions live at the right boundaries, before/after a refactor to verify the boundaries improved, or when an unfamiliar codebase needs an architectural map. Not for intra-module refactoring (see improve-code-structure), bug hunting, or feature work.
testing
Investigate and solve problems using a team of specialist agents. Use when facing complex, multi-faceted problems that benefit from parallel research and structured implementation.
data-ai
Manage stacked branches — rebase cascades, detect landed PRs, show stack status. Use when branches are stacked (B on A on main), trunk has advanced, a mid-stack branch changed, or a PR has landed and descendants need rebasing. Lightweight alternative to Graphite that infers the stack from git history.