Git upstream pr

From laurigates/claude-plugins · View interactive version

Git upstream pr is an AI agent skill from the GitHub repository laurigates/claude-plugins. Submit PRs to upstream repos from a fork — commit selection, squashing, cross-fork creation. Use when contributing changes upstream or cherry-picking fork commits.

How to use this skill

Skill file

/git:upstream-pr

Submit clean, atomic PRs to upstream repositories from fork work.

When to Use This Skill

| Use this skill when... | Use something else instead when... |

|------------------------|------------------------------------|

| Contributing changes back to the upstream repo | Committing to your own fork/repo → /git:commit |

| Cherry-picking fork commits for upstream PR (single or multi-commit, squashing) | Creating a PR within the same repo → /git:pr |

| Fork and upstream are roughly aligned | Fork has substantially diverged from upstream → /git:upstream-pr-diverged (patch-id eligibility, re-derive fallback, scrubbing) |

| Need a clean branch based on upstream/main | Working on a branch already tracking upstream |

Context

Parameters

Parse these from $ARGUMENTS:

| Parameter | Required | Description |

|-----------|----------|-------------|

| --commits sha1,sha2,... | No | Comma-separated commit SHAs to cherry-pick (interactive selection if omitted) |

| --branch name | No | Name for the upstream PR branch (auto-generated if omitted) |

| --upstream owner/repo | No | Override upstream repo (detected from remote if omitted) |

| --draft | No | Create PR as draft |

| --dry-run | No | Show what would happen without making changes |

Execution

Execute this fork-to-upstream PR workflow:

Step 1: Validate fork environment

  1. Verify this is a git repository: git rev-parse --git-dir
  2. Check if upstream remote exists (from context)
  3. If no upstream remote:
  1. Fetch upstream: git fetch upstream
  2. Record the current branch name and check for uncommitted changes
  3. If uncommitted changes exist, stash them: git stash push -m "upstream-pr: WIP before upstream PR"

Step 2: Assess fork state

Report the fork's divergence from upstream:

Fork status:
  Upstream: <upstream-repo>
  Behind upstream/main: N commits
  Ahead of upstream/main: M commits

If --dry-run is set, also show which commits would be selected and stop here.

Step 3: Select commits

If --commits provided:

If --commits not provided:

```bash

git log --oneline --format='%h %s (%cr)' upstream/main..HEAD

```

Step 4: Create clean branch from upstream/main

  1. Generate branch name if --branch not provided:
  1. Create branch from upstream/main:

```bash

git switch -c <branch-name> upstream/main

```

Step 5: Cherry-pick and squash

  1. Cherry-pick each selected commit in order:

```bash

git cherry-pick <sha1> <sha2> ...

```

  1. If cherry-pick conflicts occur:
  1. Squash all cherry-picked commits into one atomic commit:

```bash

git reset --soft upstream/main

git commit -m "<conventional commit message>"

```

  1. Use AskUserQuestion to confirm or edit the commit message

Step 6: Push to fork

git push -u origin <branch-name>

If --dry-run, show the command without executing.

Step 7: Create cross-fork PR

  1. Determine the upstream repo (from --upstream or detected remote)
  2. Determine the fork owner (from origin remote URL)
  3. Create the PR:

```bash

gh pr create \

--repo <upstream-owner/upstream-repo> \

--base main \

--head <fork-owner>:<branch-name> \

--title "<conventional commit title>" \

--body "<PR description>"

```

Add --draft if the flag was provided.

  1. Report the PR URL to the user

Step 8: Restore working state

  1. Switch back to the original branch:

```bash

git switch <original-branch>

```

  1. If changes were stashed in Step 1, pop them:

```bash

git stash pop

```

  1. Report completion summary:

```

Upstream PR created:

PR: <url>

Branch: <branch-name>

Commits: N cherry-picked, squashed into 1

Original branch restored: <branch>

```

Error Handling

| Error | Recovery |

|-------|----------|

| Cherry-pick conflict | Show conflicted files, reference git-conflicts skill |

| Push rejected | Check if branch already exists on fork; suggest --branch override |

| No upstream remote | Auto-detect from gh repo view --json parent or ask user |

| Upstream/main not found | Try upstream/master; ask user for correct branch name |

| No commits ahead of upstream | Report "Nothing to contribute" and exit |

Agentic Optimizations

| Context | Command |

|---------|---------|

| Divergence check | git rev-list --left-right --count upstream/main...HEAD |

| Commits ahead | git log --oneline --format='%h %s' upstream/main..HEAD |

| Validate SHA | git rev-parse --verify --short <sha> |

| Fork owner | git remote get-url origin \| sed -E 's#.*github.com[:/]##; s#\.git$##; s#/.*##' |

| Upstream repo | git remote get-url upstream \| sed -E 's#.*github.com[:/]##; s#\.git$##' |

| Cross-fork PR | gh pr create --repo <upstream> --head <fork-owner>:<branch> |

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.