pr-anywhere
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePR Anywhere
PR Anywhere
Make a change to any GitHub repository and open a pull request, from any terminal.
Always works in the ghq-managed clone so behaviour is identical everywhere and never
disturbs whatever checkout you happen to be sitting in.
无需在本地检出仓库,即可从任意终端修改任意GitHub仓库并创建拉取请求(PR)。
始终在ghq管理的克隆仓库中操作,确保在所有终端的行为一致,且绝不会干扰当前终端中已检出的任何仓库。
Steps (follow strictly)
步骤(严格遵循)
1. Parse the arguments
1. 解析参数
The first token of is the target repository when it looks like
(or a full GitHub URL). Everything after it is the change to make.
argsowner/repo- No first token: ask the user which repository to change. Do not guess from the current directory — this skill is meant to be run from anywhere, so the current checkout says nothing about the intended target.
owner/repo - Repository given but no change described: ask what to change.
当的第一个参数格式为(或完整GitHub URL)时,该参数即为目标仓库,后续所有内容为需要执行的修改。
argsowner/repo- 若第一个参数不是格式:询问用户要修改哪个仓库。请勿从当前目录猜测——此工具旨在从任意位置运行,因此当前检出的仓库与目标仓库无关。
owner/repo - 已指定仓库但未描述修改内容:询问用户具体要进行哪些修改。
2. Preflight: gh auth and ghq
2. 预检:gh 身份验证与 ghq
bash
gh auth statusIf fails, STOP and tell the user to run , then wait.
gh auth status! gh auth loginbash
command -v ghq || mise use -g ghq@latestIf fails to resolve, fall back to .
mise use -g ghq@latestmise use -g ubi:x-motemen/ghqbash
gh auth status如果执行失败,立即停止操作并告知用户运行,等待用户完成后再继续。
gh auth status! gh auth loginbash
command -v ghq || mise use -g ghq@latest如果无法解析, fallback 到。
mise use -g ghq@latestmise use -g ubi:x-motemen/ghq3. Resolve the repository's facts
3. 获取仓库信息
Never assume the default branch is , and never assume you can push to it.
mainbash
gh repo view <owner/repo> --json defaultBranchRef,viewerPermission- — the base branch for the PR.
defaultBranchRef.name - —
viewerPermission,ADMIN, orMAINTAINmeans you can push a branch directly to origin.WRITE,TRIAGE, orREADmeans you must fork (step 7).NONE
If the command fails, the repo does not exist or is not visible to this account.
Report that and stop.
切勿默认分支是,也不要假设你拥有推送权限。
mainbash
gh repo view <owner/repo> --json defaultBranchRef,viewerPermission- — PR的基准分支。
defaultBranchRef.name - — 若为
viewerPermission、ADMIN或MAINTAIN,则可直接向源仓库推送分支;若为WRITE、TRIAGE或READ,则必须先fork仓库(步骤7)。NONE
如果该命令执行失败,说明仓库不存在或当前账号无访问权限。请告知用户并停止操作。
4. Get (clone or update) the repository
4. 获取(克隆或更新)仓库
bash
ghq get -u github.com/<owner>/<repo>
repo="$(ghq list --full-path --exact github.com/<owner>/<repo>)"
cd "$repo"bash
ghq get -u github.com/<owner>/<repo>
repo="$(ghq list --full-path --exact github.com/<owner>/<repo>)"
cd "$repo"5. Sync the base branch and create a working branch
5. 同步基准分支并创建工作分支
Always branch off the fresh default branch — never edit it directly, never push to it.
bash
git switch <default-branch>
git pull --ff-only
git switch -c "<type>/<slug>"- :
<type>/feat/fix/refactor/docs(match the change)chore - : short kebab-case summary, e.g.
<slug>,feat/add-ripgrepfix/install-typo
If the branch already exists from a prior run, pick a new slug (append , etc.).
-2始终基于最新的默认分支创建新分支——绝不要直接编辑默认分支,也不要向其推送内容。
bash
git switch <default-branch>
git pull --ff-only
git switch -c "<type>/<slug>"- :
<type>/feat/fix/refactor/docs(根据修改类型选择)chore - : 简短的连字符分隔式摘要,例如
<slug>、feat/add-ripgrepfix/install-typo
如果该分支在之前的操作中已存在,请使用新的slug(例如追加等)。
-26. Learn the repo's conventions, then apply the edit
6. 了解仓库规范,然后执行修改
Before editing, read whatever the repository says about itself — ,
, , — and check
for the commit message style actually in use. Follow them
over any habit of your own.
CLAUDE.mdAGENTS.mdCONTRIBUTING.md.github/PULL_REQUEST_TEMPLATE.mdgit log --oneline -20Make the requested change with the normal edit tools. Keep it focused — one logical
change per PR.
Run whatever check the repo defines (lint, test, typecheck) if one is obvious from
its config or CI workflow. Report failures rather than working around them.
在修改前,请阅读仓库中的相关文档——如、、、——并查看了解仓库实际使用的提交信息格式。请严格遵循仓库规范,而非个人习惯。
CLAUDE.mdAGENTS.mdCONTRIBUTING.md.github/PULL_REQUEST_TEMPLATE.mdgit log --oneline -20使用常规编辑工具完成请求的修改。保持修改聚焦——每个PR仅包含一个逻辑修改。
如果从仓库配置或CI工作流中可明显看出需要执行检查(如lint、测试、类型检查),请运行相应检查。若检查失败,需告知用户而非自行绕过。
7. Push
7. 推送分支
With write access (step 3 said / / ):
ADMINMAINTAINWRITEbash
git push -u origin "<branch>"Without write access — fork first, and push the branch to the fork:
bash
gh repo fork --remote --remote-name fork
git push -u fork "<branch>"拥有写入权限(步骤3中权限为 / / ):
ADMINMAINTAINWRITEbash
git push -u origin "<branch>"无写入权限 — 先fork仓库,再将分支推送到fork的仓库:
bash
gh repo fork --remote --remote-name fork
git push -u fork "<branch>"8. Open the PR
8. 创建PR
bash
gh pr create --base <default-branch> --title "<type>: <summary>" --body "<why>"Add when pushing from a fork, so the PR lands on the upstream
repository rather than the fork.
--repo <owner/repo>Write the body yourself — state what changed and why. Use only when the
commit message already says everything the reviewer needs.
--fillbash
gh pr create --base <default-branch> --title "<type>: <summary>" --body "<why>"如果是从fork的仓库推送分支,请添加参数,确保PR提交到上游仓库而非fork的仓库。
--repo <owner/repo>请自行编写PR正文——说明修改内容及原因。仅当提交信息已包含评审所需的全部内容时,才可使用参数。
--fill9. Report
9. 反馈结果
Output the PR URL returned by .
gh pr create输出返回的PR链接。
gh pr createGotchas
注意事项
- Never touch the current checkout: even when invoked from inside a checkout of the target repo, work in the ghq clone. This keeps behaviour identical on every terminal and avoids disturbing uncommitted work.
- The default branch is not always : resolve it in step 3. Hardcoding
mainfails onmainrepos and on any repo using a release branch as default.master - gh not authenticated: step 8 fails cryptically. Verify with in step 2 first.
gh auth status - is checked by exit code:
command -v ghqonly installs when truly missing.|| mise use ... - : fails loudly if the local clone diverged from origin (e.g. leftover commits on the default branch). If it fails,
git pull --ff-onlyafter confirming there is nothing to keep.git reset --hard origin/<default-branch> - Branch already exists: fails. Reuse it (
git switch -c) only if it is yours and clean, otherwise choose a new slug.git switch <branch> - A stale ghq clone of a fork: if lands on a clone whose
ghq getis your fork rather than upstream,originstill describes upstream whilegh repo viewgoes to the fork. Checkgit push originwhen the PR base looks wrong.git remote -v
- 绝不触碰当前检出的仓库:即使在目标仓库的检出目录中调用此工具,也需在ghq克隆的仓库中操作。这样可确保在所有终端的行为一致,并避免干扰未提交的工作。
- 默认分支不一定是:请在步骤3中确认默认分支。硬编码
main会导致在使用main或其他发布分支作为默认分支的仓库上操作失败。master - gh未完成身份验证:步骤8会出现模糊的失败信息。请在步骤2中先通过验证身份。
gh auth status - 通过退出码检查:
command -v ghq仅在ghq确实缺失时才会安装。|| mise use ... - :如果本地克隆与源仓库出现分歧(例如默认分支上存在遗留提交),该命令会直接失败。若失败,在确认无需要保留的内容后,执行
git pull --ff-only。git reset --hard origin/<default-branch> - 分支已存在:会失败。仅当分支属于你且状态干净时才可复用(
git switch -c),否则请选择新的slug。git switch <branch> - ghq克隆的fork仓库已过期:如果获取的克隆仓库的
ghq get是你的fork而非上游仓库,origin仍会显示上游仓库信息,但gh repo view会推送到fork的仓库。当PR基准分支看起来异常时,请检查git push origin。git remote -v