{"data":{"slug":"discovered-46340f5b21dadaee39122ef71d9c79208b713555d769f659","title":"Upstream Sync","summary":"Catch a fork up with the third-party project it tracks and triage what upstream shipped. This includes analyzing which upstream changes touch the fork's patches and identifying new upstream features that may be useful.","url":"https:\/\/skillshunter.net\/skills\/discovered-46340f5b21dadaee39122ef71d9c79208b713555d769f659","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-46340f5b21dadaee39122ef71d9c79208b713555d769f659","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-46340f5b21dadaee39122ef71d9c79208b713555d769f659.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-46340f5b21dadaee39122ef71d9c79208b713555d769f659\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before running, confirm the upstream ref and patch branch from the fork's remotes and branches. Fetch all changes with `git fetch --all` to ensure accurate ahead\/behind counts. If the fetch fails, stop and report the failure.","instructions":"---\nname: upstream-sync\ndescription: >-\n  Catch a fork up with the third-party project it tracks and triage what upstream shipped.\n  TRIGGER when: pulling, merging or rebasing upstream changes into a fork with analysis; which upstream\n  changes touch the fork's patches; or which new upstream features are useful.\n  DO NOT TRIGGER when: the branch only lags its own remote (`\/pull`), the repo is not a fork, or filing\n  an issue or PR upstream.\n---\n\n# Upstream sync\n\nA fork carries the user's patches on top of somebody else's project. Each upstream catch-up asks three\nquestions, in this order: what in the incoming range collides with the fork's patches, what the fork should\nlook like after it, and which of upstream's new features matter to the user's own work. The first two decide\nthe integration; the third is a discussion that outlives this session, so it lives on a page.\n\nRead `~\/.claude\/skills\/shared\/bash-rules.md` for bash command constraints, and\n`~\/.claude\/learnings\/git-resolving-rebase-conflicts.md` before resolving anything.\n\n## Context\n- Remotes: !`git remote -v`\n- Branches: !`git branch -vv`\n- Status: !`git status --short; echo \"(end of status)\"`\n\n## 1. Establish the topology\n\n**Context** is gathered before this skill's `git fetch --all`, so its ahead\/behind counts are stale; measure after fetching.\n\nRead the project memory first (`.claude\/memory\/`): a fork note usually records which remote is the\nuser's, which is the third party's, which branch carries the patches, and how the app is installed.\nConfirm it against **Remotes** and **Branches** rather than trusting it. Name, for the rest of the run:\n\n- **upstream ref** \u2014 the third party's remote-tracking ref, e.g. `upstream\/main`. It may be the patch branch's\n  own `@{upstream}` (remotes inverted). Never a local mirror branch such as `main`, which can lag it.\n- **patch branch** \u2014 the branch holding the fork's commits, and the remote it is pushed to.\n- **integration method** \u2014 rebase or merge. Read it from the fork's own history:\n  `git log --merges --oneline <upstream ref>..<patch branch>` empty means rebase. Unscoped, the log lists\n  upstream's own PR merges and reads as \"merge\". Do not switch methods unasked.\n\nFetch with `git fetch --all || echo FETCH-FAILED`. A failed fetch makes every later count unmeasured; stop\nand say so.\n\nTrust git for \"is there anything new\", never the app's own update check: a fork's version string can blind it.\n\n## 2. Measure the range\n\n1. Behind\/ahead: `git rev-list --left-right --count <upstream ref>...<patch branch>`.\n2. Fork-only commits: `git log --oneline <upstream ref>..<patch branch>`.\n3. Version range: the merge base's nearest tag to the upstream ref's tag (`git describe --tags`), and the\n   upstream `CHANGELOG.md` sections in that range (`git show <upstream ref>:CHANGELOG.md`). Without tags or\n   a changelog, read every subject in `git log <merge-base>..<upstream ref>`, not only `feat:`\/`fix:` ones:\n   a non-conventional subject can be the biggest feature. For a `(#N)` subject, `gh pr view N --repo <upstream>`.\n\n## 3. Find what collides with the fork\n\nWith `B=$(git merge-base <patch branch> <upstream ref>)`, intersect the files each side changed:\n`comm -12 <(git diff --name-only $B <patch branch> | sort) <(git diff --name-only $B <upstream ref> | sort)`.\nThen predict the textual conflicts without touching the tree: `git merge-tree --write-tree --name-only <upstream ref> <patch branch>`.\nThat predicts a merge. A rebase replays each commit, so a file touched by N fork commits can conflict N times\nwhere merge-tree reports once. For the exact picture on a rebase fork, rebase in a scratch worktree under\nthe gitignored `tmp\/` and remove it afterwards.\n\nFind fork commits upstream already took (the user's own PR, merged): `git cherry -v <upstream ref> <patch branch>`;\na `-` line is patch-identical upstream.\n\nFor every fork commit, read its diff beside upstream's diff of the same files and classify it:\n\n| Class | Sign | What the fork commit becomes |\n|---|---|---|\n| Independent | no shared files | rebases as is |\n| Upstream merged it | `-` in `git cherry` | the rebase drops it; update any memory recording the PR as open |\n| Upstream built the same mechanism | same apply loop, stamp, config key, under upstream's names | shrink the fork commit to what upstream lacks; take upstream's version of the rest |\n| Upstream fixed the reason | the fork patch's symptom is gone upstream | propose dropping it; verify the symptom before saying so |\n| Ordered resources | both sides add numbered patches\/migrations | give the fork's their own series named after the fork owner (`<owner>-NNNN`), sorting after upstream's, so an upstream addition never renames them; amend any doc that says \"the final patch\" |\n| **Semantic interaction** | no shared lines, but upstream added code or tests in the area the fork patch changes behaviour of | flag it; this is the one that passes the rebase and fails CI |\n\nThe last row needs a deliberate search over the lines upstream added, for the symbols the fork patch touches:\n`git diff $B <upstream ref> -- <src dirs> <test dirs> | grep '^+' | grep -E '<symbols>'`. Real case: a fork libghostty patch treating clicks-only\nmouse mode as uncaptured rebased cleanly, then failed two upstream tests added in the same range, because\nthe app still asked an unpatched \"is the mouse captured\" query and the two halves disagreed.\n\nWhen the fork carries patches against a vendored dependency, prove they stack: a scratch checkout of the\npinned revision under the repo's gitignored `tmp\/`, apply upstream's patches, then `git apply --check` the\nfork's. Delete the scratch checkout afterwards.\n\nCheck whether the fork's patches still serve a purpose upstream's new features rely on: upstream docs\nsaying a workaround is still needed is evidence the patch stays.\n\n## 4. Inventory how the user uses the product\n\nThe feature triage is only as good as this. Gather, read-only:\n\n- **Transcripts:** count CLI subcommands across every project, on the machine that runs the product\n  (over SSH when that is the other one; otherwise report the count unmeasured), e.g.\n  `grep -ohE \"<tool>ctl(\\.exe)? [a-z-]+( [a-z-]+)?\" ~\/.claude\/projects\/*\/*.jsonl | sort | uniq -c | sort -rn | head -25`.\n- **Integrating repos:** delegate one `Explore` agent to list every call the user's other repos make into\n  the product (dashboards, skills, scripts), with file, function and what each call is used for. A call\n  existing is not relevance: a `session new` that only runs an attach script never cares which cwd it\n  opens in. When the product is a terminal or app with a live control socket, its prompt carries the\n  project's own safety line verbatim (agterm's:\n  \"never execute `agterm`\/`agtermctl` against the default socket, never launch or quit the app, static\n  reading only.\"); for a product with none written down, adapt that one.\n- **Memories and memos** of the integrating repos that name a missing capability: an upstream feature may\n  answer an ask recorded as withdrawn or impossible.\n\nRead the installed version with the product's own version command (e.g. `<tool>ctl version`) on the machine\nthat runs it: a feature is unusable until the user redeploys there.\n\n## 5. Report, then stop\n\nOne reply, two sections:\n\n1. **Incoming changes that overlap your fork** \u2014 per fork commit, its class from step 3 and the concrete\n   rework, numbered. Say what was verified (apply-check, merge-tree) and what was inferred.\n2. **New features useful for your work** \u2014 the top few with one line each tying them to an inventory\n   finding; say the full list comes on a page after integration.\n\nEnd by asking to integrate. A diverged branch is never rebased or merged without that answer.\nThe session that ran steps 1-5 asks it, and names where step 6 will run.\n\n## 6. Integrate\n\nSteps 1-5 may run on either machine; step 6 runs where the patch branch is owned. When that is another\nsession, hand it off through the `peer` skill with the step 3 plan and the user's answer. The receiver\nre-measures (rev-list, `git cherry`, merge-tree) before rebasing, since the range may have moved.\n\n1. Rebase or merge by the method from step 1. Resolve per the step 3 plan; mid-rebase `--ours` is the\n   upstream side (the learnings file has the detail).\n2. Update the fork's own record of its patches in the same change: the patches README, the fork memory note,\n   and any fork version bump. Commit these through `shared\/commit.py`, so the branch carries its own\n   description whenever it is pushed.\n   A rebase also orphans the review bookmark (`refs\/review\/last` is no longer an ancestor of HEAD), so the next\n   `review-auto` run cannot be recorded. Review from the upstream ref, then point the local bookmark at it\n   (`git update-ref refs\/review\/last <upstream ref> <old bookmark>`) so `review_scope.py mark --base <upstream\n   ref>` and `advance` work. The push after the branch's force push then replaces origin's old bookmark, since no\n   branch on origin holds it any more; while one still does, `review_scope.py push` refuses and names it.\n3. Rebuild whatever the dependency stamps say is stale, then run the project's real gate (its\n   `commit-checks.sh` or the build plus tests its CLAUDE.md names). The patch branch is pushed only once it\n   is green. When the gate only runs on a machine other than the one holding the patch branch, it goes to\n   the live session there (the `peer` skill), not skipped. That session can only build what is pushed, so\n   push the rebased branch to a scratch branch on the fork for it, and delete the scratch branch once it\n   reports. Both pushes report the review bookmark's forecast before and status after, as\n   `~\/.claude\/skills\/shared\/review-bookmark-status.md` describes.\n4. A semantic interaction from step 3 that the gate confirms is fixed in the fork's patch, not by editing\n   upstream's code. Upstream tests asserting upstream's behaviour get a one-line skip naming the fork patch,\n   so each future sync conflicts on one line. Ask before skipping.\n5. Ask when to push: now, or after the feature discussion. The integration is already committed (item 2), so\n   this decides only when the push runs. A merged branch pushes plainly through `shared\/push.py`. A rebased\n   one goes out as \"Pushing a rebased fork needs a force push\" says, never through `\/wrap-up` or\n   `push.py`: `\/wrap-up`'s sync reads the rebased branch as diverged.\n\n**Pushing a rebased fork needs a force push.** `shared\/push.py` runs a plain push, which is refused. Propose\n`git push --force-with-lease=<branch>:<remote>\/<branch> <remote> <branch>` and run it only on a yes, doing\nby hand what `push.py` does around a push, as `shared\/sync-and-push.md`'s \"After the push\" lists, the\nbookmark's forecast before it included. Query CI with an explicit `--repo <fork owner>\/<name>`: in a fork\n`gh` resolves to upstream by default. A macOS job cancelled after ~15 minutes without a step is runner\nshortage, so the run measured nothing; say so instead of calling it green or red.\n\nNever tag or release from the fork: version tags are upstream's.\n\n## 7. The features page\n\nWrite `tmp\/<project>-v<from>-v<to>-features.html` (gitignored scratch), following system light\/dark:\n\n- One numbered card per new feature, grouped by theme, bug fixes left out. Keep numbers stable for the\n  whole discussion: the user refers to items by number.\n- Under each card, an assessment against the step 4 inventory, tagged `improves existing`,\n  `new capability` or `low relevance`, with the reason. Highlight the strongest.\n- Add, as item 0, anything older than the range that the inventory shows the user believes is missing.\n- A **Discussion context** section at the bottom: fork state (running version, what the fork patches now\n  change, CI status and the retry command, what was sent to other sessions), the integration inventory, and\n  points already discussed. It is what lets the discussion survive `\/clear`.\n\nPublish it with `python3 ~\/.claude\/skills\/shared\/tailnet_publish.py publish <file>` and hand over the URL it\nprints. Inside agterm, also offer to open it in an overlay (the `agterm` skill).\n\n## 8. The discussion\n\nGo one item at a time, at the user's pace. For each decided item:\n\n1. Move it from a **Pending** table to a **Processed** one at the bottom, with a one-line decision.\n2. Carry out the decision's routing: a memo in this repo (`\/memo`), a message to the live session owning\n   another repo (`peer` skill; no approval needed), or nothing. A memo for another repo goes through that\n   repo's session, never written into its tree from here.\n3. Update the page and say what changed in it.\n\nWhen the user wants to break off, update the Discussion context and give them, in a fenced block, the line\nthat resumes it:\n\n```\nread tmp\/<page>.html, including the discussion context at the bottom, and let's continue discussing it\n```\n\nThe page is temporary: it ends when nothing pending is left that the user values. Do not propose keeping\nit as a long-term document.\n\n## Out of scope\n\n- Filing issues or PRs upstream: outward communication, drafted and approved per message.\n- Deploying or restarting the installed app: offer it, with the project's own deploy rules.\n- Tagging or releasing.\n- A fork that is only behind its own remote: `\/pull`.\n","use_cases":["Syncing a fork with upstream changes","Identifying conflicts between upstream and forked commits","Analyzing new upstream features for potential integration"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/AnotherSava\/claude-code-common\/blob\/1a7f9f9cce53f6946ae1e3a9cc0733f2524a4b93\/claude\/skills\/upstream-sync\/SKILL.md","source_commit":"1a7f9f9cce53f6946ae1e3a9cc0733f2524a4b93","license":null,"version":null,"listing_approved_at":"2026-12-01","created_at":"2026-11-30T08:08:49.000000Z","updated_at":"2026-12-01T12:48:20.000000Z","seo_title":"Upstream Sync for Forked Repositories","seo_description":"Sync a fork with its upstream project, analyze conflicts, and identify useful upstream changes. This process helps maintain alignment with the original project while tria","seo_keywords":["git upstream sync","fork integration","merge conflicts","rebase upstream","upstream changelog analysis"]}}