agentleFS
MicrosoftKnown publishermicrosoft/Olive/skills/dev/copy-fork-pr/SKILL.md

copy-fork-pr

Skill2.4k starsChanged 14 months agoMITView on GitHub

Copy PR #<number>. Use when a user says "Copy PR #123" or otherwise provides a PR number to copy its fork-owned branch locally, push a destination-owned branch, and create an independent draft PR.

  • Commits and pushes

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Do not switch a dirty worktree, overwrite an existing branch, or force-push.

    line 17
  2. Distinctive:

    Do not silently use another fork when destination write access is missing.

    line 46
  3. Very specific:

    Treat every resolved value as untrusted data.

    line 59
  4. Distinctive:

    Stop if the local or destination branch already exists.

    line 71
  5. Very specific:

    Write the PR body to a temporary file with the agent's file-writing tool.

    line 81

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Copy a fork PR branch and create a draft PR

Input: PR_NUMBER only. Run from the destination repository clone. Do not accept a branch URL fallback.

Rules:

  • Do not switch a dirty worktree, overwrite an existing branch, or force-push.
  • The copied branch must be destination-owned.
  • The PR must be a draft titled [DO NOT MERGE] Copy of #<PR_NUMBER>.

Workflow

1. Check access

Validate that PR_NUMBER contains ASCII digits only before using it in any command. Never use eval.

git --version
gh --version
gh auth status --hostname github.com
DEST_REPO="$(gh repo view --json nameWithOwner --jq '.nameWithOwner')"
DEST_OWNER="${DEST_REPO%%/*}"
PERMISSION="$(gh repo view --json viewerPermission --jq '.viewerPermission')"
git remote get-url --push origin

Require viewerPermission to be WRITE, MAINTAIN, or ADMIN. Otherwise stop. For authentication help:

gh auth login --hostname github.com
gh auth refresh --hostname github.com --scopes repo
gh auth setup-git                 # HTTPS remote
ssh -T git@github.com             # SSH remote

Do not silently use another fork when destination write access is missing.

2. Resolve the PR

SOURCE_OWNER="$(gh pr view "${PR_NUMBER}" --repo "${DEST_REPO}" --json headRepositoryOwner --jq '.headRepositoryOwner.login')"
SOURCE_REPO="$(gh pr view "${PR_NUMBER}" --repo "${DEST_REPO}" --json headRepository --jq '.headRepository.name')"
SOURCE_BRANCH="$(gh pr view "${PR_NUMBER}" --repo "${DEST_REPO}" --json headRefName --jq '.headRefName')"
BASE_BRANCH="$(gh pr view "${PR_NUMBER}" --repo "${DEST_REPO}" --json baseRefName --jq '.baseRefName')"
DEST_BRANCH="${SOURCE_BRANCH}"
SOURCE_URL="https://github.com/${SOURCE_OWNER}/${SOURCE_REPO}.git"

Treat every resolved value as untrusted data. Keep every expansion quoted. Stop if any field is empty or if SOURCE_OWNER equals DEST_OWNER; this workflow is only for fork-owned PRs.

3. Copy and push

git status --short --branch
git worktree list --porcelain
git branch --list "${DEST_BRANCH}"
git ls-remote origin "refs/heads/${DEST_BRANCH}"

Stop if the local or destination branch already exists. Then copy and push without checking out the branch:

git fetch "${SOURCE_URL}" "refs/heads/${SOURCE_BRANCH}:refs/heads/${DEST_BRANCH}"
git push --dry-run origin "refs/heads/${DEST_BRANCH}:refs/heads/${DEST_BRANCH}"
git push --set-upstream origin "refs/heads/${DEST_BRANCH}:refs/heads/${DEST_BRANCH}"

4. Create the draft

Write the PR body to a temporary file with the agent's file-writing tool. Do not interpolate generated body text into shell source and do not use a shell heredoc. Set PR_BODY_FILE to that file's path.

gh pr list \
  --repo "${DEST_REPO}" \
  --head "${DEST_BRANCH}" \
  --state all \
  --json number,title,state,isDraft,url,headRepositoryOwner
gh pr create \
  --repo "${DEST_REPO}" \
  --base "${BASE_BRANCH}" \
  --head "${DEST_BRANCH}" \
  --draft \
  --title "[DO NOT MERGE] Copy of #${PR_NUMBER}" \
  --body-file "${PR_BODY_FILE}"

Reuse an existing destination-owned PR instead of creating a duplicate. Delete the temporary body file after PR creation.

5. Verify

gh pr view "${COPIED_PR_NUMBER}" \
  --repo "${DEST_REPO}" \
  --json number,title,url,state,isDraft,baseRefName,headRefName,headRepositoryOwner

Confirm:

  • isDraft is true;
  • title is exactly [DO NOT MERGE] Copy of #<PR_NUMBER>;
  • headRepositoryOwner, headRefName, and baseRefName match the derived destination values.

Report the original PR, copied branch, and draft PR URL.

Download now (ZIP)

Trending

More talk lately.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 1 mentionApr 2026: 2 mentionsMay 2026: 4 mentionsJun 2026: 1 mentionJul 2026: 3 mentionsAug 2026: 0 mentionsSep 2026: 2 mentionsOct 2026: 4 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the microsoft/Olive repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about microsoft/Olive

The biggest 5 of 37 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 37

Talked about on GitHub, Hacker News and Stack Overflow (37 times).

On GitHub · 35

30 more on GitHub

On Stack Overflow · 1

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.