/git-plugin:git-fork-workflowfrom git-plugin
Manages forked repositories: detects divergence, recommends sync strategies (fast-forward, rebase), and helps set up upstream remotes for clean contributions.
Ships in git-plugin. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Expert guidance for managing forked repositories, synchronizing with upstream, and contributing back cleanly.
Run this first to detect the upstream remote, compute ahead/behind via
git rev-list, and get a recommended sync strategy (a pure function — it
runs no mutations):
bash "${CLAUDE_SKILL_DIR}/scripts/git-fork-workflow.sh" --home-dir "$HOME"
Parse STATUS= and ISSUES: from the output. It emits IS_FORK,
UPSTREAM / ORIGIN, BEHIND / AHEAD (from
git rev-list --left-right --count upstream/main...origin/main), and
RECOMMENDED_STRATEGY (one of in-sync, fast-forward, ahead-only,
rebase, not-a-fork). The strategy is a recommendation only — executing
any destructive sync (reset, rebase, force-push) stays your call, per the
strategy prose below.
| Use this skill when... | Use git-upstream-pr instead when... |
|---|---|
| Understanding fork remote architecture | Ready to submit a PR to upstream |
| Diagnosing fork divergence from upstream | Need step-by-step PR creation workflow |
| Syncing fork's main with upstream | Cherry-picking specific commits for upstream |
| Deciding on a sync strategy | Creating a cross-fork PR via gh CLI |
| Contributing from an environment that can't reach upstream | Upstream is directly reachable for a normal cross-fork PR |
Forks use two remotes:
| Remote | Points To | Purpose |
|---|---|---|
origin | Your fork (you/repo) | Push your work here |
upstream | Original repo (owner/repo) | Pull updates from here |
# Verify remotes
git remote -v
# Add upstream if missing
git remote add upstream https://github.com/owner/original-repo.git
# Verify
git fetch upstream
git remote -v
Remote-URL one-liners for telling fork from upstream: REFERENCE.md § Identifying Fork vs Upstream.
When you squash-merge branches into your fork's main, the commit SHAs differ from upstream's commits. This creates divergence even when the code content is identical.
The data-gathering script (above) fetches both remotes and computes the
ahead/behind counts — read BEHIND and AHEAD from its output. To view the
specific divergent commits behind those counts:
# Show divergent commits
git log --oneline upstream/main..origin/main # Commits on fork not on upstream
git log --oneline origin/main..upstream/main # Commits on upstream not on fork
How to read each BEHIND/AHEAD combination: REFERENCE.md § Reading the Counts.
# Syncs fork's default branch with upstream via GitHub API
gh repo sync owner/fork-repo
# Then pull locally
git pull origin main
Best when: fork has no unique commits worth preserving on main.
git fetch upstream
git merge --ff-only upstream/main
Best when: fork's main has not diverged. Fails cleanly if diverged (no messy merge commits).
git fetch upstream
git reset --hard upstream/main
git push --force-with-lease origin main
Best when: fork's main has diverged and you want to discard fork-only commits. Destructive - ensure no unique work is on main.
git fetch upstream
git rebase upstream/main
git push --force-with-lease origin main
Best when: fork has unique commits on main that should sit on top of upstream's history.
The script's RECOMMENDED_STRATEGY maps the BEHIND/AHEAD counts to a
strategy keyword via a pure function; use it as the starting point and confirm
against this table before running any destructive command:
RECOMMENDED_STRATEGY | Situation | Strategy |
|---|---|---|
in-sync | 0 behind, 0 ahead | Nothing to do |
fast-forward | Behind only, fork main clean | Fast-forward or gh repo sync |
ahead-only | Ahead only, nothing to pull | No sync needed; fork leads upstream |
rebase | Diverged, unique work worth keeping | Rebase (Strategy 4) |
| (diverged, work expendable) | Unique work expendable / match upstream exactly | Hard reset (Strategy 3) |
| (unsure) | Not sure | Try fast-forward first; it fails safely if diverged |
The recommendation never executes a sync — picking and running Strategy 3 (hard reset) or 4 (rebase + force-push) stays your decision.
Branch from upstream/main, not from your fork's main. This completely bypasses fork divergence:
git fetch upstream
git switch -c feat/my-contribution upstream/main
# Cherry-pick, code, or apply changes here
git push -u origin feat/my-contribution
# Create cross-fork PR targeting upstream
See git-upstream-pr for the complete workflow.
When the environment cannot reach upstream directly — e.g. a Claude Code session whose repository scope only includes your fork, so issues/PRs against owner/repo are denied — don't let that block development. Stage the contribution in your fork's main, then resubmit upstream from a session that can reach it.
Stage in the fork. Branch (ideally from upstream/main), implement, open a PR into your fork's main, self-review, and merge. The change is now landed and usable immediately, independent of upstream reachability.
Contain the divergence. Merging into fork main diverges it from upstream/main (different SHAs — the Divergence Problem above). That is the accepted cost of staging. Keep it bounded by periodically pulling upstream/main back in (rebase or merge) so the fork doesn't rot.
Resubmit cleanly — never PR fork:main → upstream:main. That drags every staged commit plus the divergence into one PR. Instead, from a session that can reach upstream, branch fresh from upstream/main and cherry-pick only the one contribution's commit(s), then open the cross-fork PR (REFERENCE.md § Cross-Fork PR Syntax). Each upstream PR stays atomic and reviewable — what maintainers actually accept.
Track upstream status. Stamp staged commits so a later session knows what still needs a PR:
Upstream-status: pending # staged in fork, not yet submitted
Upstream-PR: https://github.com/owner/repo/pull/NN # once submitted
List what's still pending with git log --grep='Upstream-status: pending' upstream/main..origin/main.
Backtick owner/repo#N, owner/repo@sha and upstream URLs in a fork-internal PR or issue body, or upstream gets a backlink before you submit. Details and a pre-publish check: REFERENCE.md § Keep the staging PR's text from reaching upstream.
| Situation | Approach |
|---|---|
| You can reach upstream now | Branch from upstream/main, open the cross-fork PR directly (Golden Rule above) |
| You cannot reach upstream from this environment | Stage in fork main now; cherry-pick onto an upstream/main branch and PR later |
The staging pattern is the Golden Rule deferred — it still ends with a clean upstream/main-based branch; it just buys you an unblocked checkpoint in between.
gh pr create --repo owner/upstream-repo --head your-username:<branch>; full form: REFERENCE.md § Cross-Fork PR Syntax.
Secondary recipes (check for a fork, periodic sync, upstream changes since last sync): REFERENCE.md § Common Patterns.
| Context | Command |
|---|---|
| Divergence count | git rev-list --left-right --count upstream/main...origin/main |
| Fork ahead commits | git log --oneline --format='%h %s' upstream/main..origin/main |
| Fork behind commits | git log --oneline --format='%h %s' origin/main..upstream/main |
| Quick sync check | git fetch upstream && git merge --ff-only upstream/main |
| Remote listing | git remote -v |
What SKILL.md sets; muted values are Claude Code's defaults
52 skills in this plugin
/deadbranchdeadbranch CLI for stale-branch cleanup — dry-run preview, TUI or non-interactive delete, protects main/develop/WIP. Use when asked to clean up branches, prune branches, or remove stale branches./external-pr-trustAuthorship as a precondition of merging — bot vs stranger classification, what a merge executes, the merge-guard hook. Use when bulk-merging PRs, or when a merge is denied for a non-self author./gh-cli-agenticgh CLI commands with JSON output for agents. Use when querying PRs, issues, runs, or repo metadata; inspecting PR checks; fetching failed CI logs; or mapping a github.com URL to an API call./git-api-prGitHub API PR creation without local git. Use when submitting file changes as a PR without local commits — quick fixes, typos, config updates, or bypassing local git state./git-branch-namingBranch names: type prefix (feat/, fix/, chore/), issue number, kebab-case. Use when picking a name for a new branch or setting a repo's branch-naming convention./git-branch-pr-workflowBranch management and PR workflows — git switch/restore, GitHub MCP. Use when creating branches, opening PRs, or working with feature branches.npx claudepluginhub laurigates/claude-plugins --plugin git-pluginOther plugins' skills for the same job