pull
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePull
拉取同步
Purpose
用途
- Bring the current branch up to date with the remote default branch (typically ) using a merge (not rebase, unless AGENTS.md or team policy says otherwise).
origin/main - Resolve merge conflicts safely and verify with (or the repo’s documented checks).
pnpm lint && pnpm test - Prefer rerere and clear conflict styles so repeated conflicts are easier to handle.
- 使用合并(而非变基,除非AGENTS.md或团队政策另有规定)的方式,让当前分支与远程默认分支(通常为)保持同步。
origin/main - 安全解决合并冲突,并通过****(或仓库文档中规定的检查项)进行验证。
pnpm lint && pnpm test - 优先使用rerere工具和清晰的冲突标记格式,以便更轻松地处理重复出现的冲突。
Prerequisites
前置条件
- Git remote exists and points at the expected host.
origin - You know which branch is the integration base (usually ; use the repo’s default if different).
main
- Git远程仓库已存在,且指向预期的托管平台。
origin - 你已明确集成基准分支(通常为;若仓库使用其他默认分支,则以仓库设置为准)。
main
When to Use
适用场景
- "pullして", "main を取り込んで", "同期して", or similar—when the feature branch must match (or the team base branch).
origin/main - After is rejected with non-fast-forward, or when the local branch is behind the remote tracking branch.
git push - When preparing to push and the branch needs the latest upstream changes first (often chained before push).
- 当需求为「pullして」「main を取り込んで」「同期して」或类似表述时——即功能分支必须与(或团队基准分支)保持一致的场景。
origin/main - 在**因非快进问题被拒绝后,或本地分支落后于远程跟踪分支**时。
git push - 准备推送分支前,需要先获取上游最新变更的场景(通常会在push操作前执行本操作)。
Do Not Use When
不适用场景
- The user only wants to push without merging the base (use push; if push fails, then use pull).
- The user wants to create or update a GitHub PR (use create-pr-jp).
- The goal is merging or landing an approved PR on the default branch (use a land or merge workflow skill if the workspace defines one—not this skill).
- 用户仅需推送分支而无需合并基准分支时(使用push操作;若推送失败,再使用本操作)。
- 用户需要创建或更新GitHub PR时(使用create-pr-jp操作)。
- 目标是在默认分支上合并或落地已批准的PR时(若工作区定义了相关的「land」或合并工作流技能,请使用该技能——而非本操作)。
Related Skills
相关技能
- push: After sync and green checks, publish commits to .
origin - create-pr-jp: Open or update a PR; out of scope for pull.
- push:完成同步且检查通过后,将提交发布到。
origin - create-pr-jp:创建或更新PR;本操作不包含该功能。
Procedure
操作步骤
- Ensure the working tree is safe to merge: commit or stash uncommitted work before merging.
- Enable rerere locally (recommended):
git config rerere.enabled truegit config rerere.autoupdate true
- Confirm remotes and branch: exists; the current branch is the one that should receive the merge.
origin - Fetch:
git fetch origin - Fast-forward the current branch from its remote counterpart if it exists (picks up remote-only commits before merging main):
git pull --ff-only origin "$(git branch --show-current)"
- Merge the base branch (replace if the repo uses another default):
main- Prefer for clearer conflict context.
git -c merge.conflictstyle=zdiff3 merge origin/main
- Prefer
- If conflicts appear, resolve them (see Conflict Resolution below), then:
git add <files>- or
git commitas appropriate.git merge --continue
- Verify: run , or follow
pnpm lint && pnpm test/ project scripts if they differ.AGENTS.md - Summarize for the user: hardest conflicts, how they were resolved, and any follow-ups.
- 确保工作区状态适合合并:合并前提交或暂存所有未提交的工作。
- 本地启用rerere工具(推荐):
git config rerere.enabled truegit config rerere.autoupdate true
- 确认远程仓库和分支:已存在;当前分支为需要合并基准分支的目标分支。
origin - 拉取远程变更:
git fetch origin - 如果当前分支存在远程跟踪分支,先进行快进同步(在合并main分支前,获取仅存在于远程的提交):
git pull --ff-only origin "$(git branch --show-current)"
- 合并基准分支(若仓库使用其他默认分支,替换即可):
main- 优先使用命令,以获得更清晰的冲突上下文。
git -c merge.conflictstyle=zdiff3 merge origin/main
- 优先使用
- 若出现冲突,按照下方冲突解决部分的步骤处理,然后:
git add <files>- 根据情况执行或
git commit。git merge --continue
- 验证:运行****,若仓库有自定义检查脚本,则遵循AGENTS.md或项目脚本的要求。
pnpm lint && pnpm test - 向用户总结:说明最难处理的冲突、解决方式,以及后续需要执行的操作。
Output
输出结果
- Current branch contains the merged base; conflicts resolved; (or repo equivalent) passed.
pnpm lint && pnpm test - A clear narrative of what was merged and any notable resolution decisions.
- 当前分支已合并基准分支的内容;冲突已解决;(或仓库等效检查)已通过。
pnpm lint && pnpm test - 清晰说明合并的内容,以及任何值得注意的冲突解决决策。
Usage
使用示例
Reference flow (adapt / branch names to the repo):
mainsh
git config rerere.enabled true
git config rerere.autoupdate true
git fetch origin参考流程(根据仓库情况调整或分支名称):
mainsh
git config rerere.enabled true
git config rerere.autoupdate true
git fetch originOptional: sync remote feature branch commits first
可选:先同步远程功能分支的提交
git pull --ff-only origin "$(git branch --show-current)"
git pull --ff-only origin "$(git branch --show-current)"
Merge default branch (zdiff3 for conflict readability)
合并默认分支(使用zdiff3格式提升冲突可读性)
git -c merge.conflictstyle=zdiff3 merge origin/main
git -c merge.conflictstyle=zdiff3 merge origin/main
After resolving conflicts:
解决冲突后:
git add … && git commit # or git merge --continue
git add … && git commit # 或执行 git merge --continue
pnpm lint && pnpm test
undefinedpnpm lint && pnpm test
undefinedConflict Resolution
冲突解决
- Inspect before editing:
- for conflicted files;
git status/git difffor hunks.git diff --merge - Optional: and
git diff :1:path :2:pathvs:1:for base vs ours/theirs.:3: - With , markers are
merge.conflictstyle=zdiff3ours,<<<<<<<base,|||||||,=======theirs.>>>>>>> - Infer intent on both sides; choose semantics first, then edit code.
- Prefer minimal, intention-preserving edits aligned with the branch’s purpose.
- Resolve in batches; rerun after a logical batch of files when helpful.
pnpm lint && pnpm test - Use ours/theirs only when one side should win entirely.
- Generated files: fix sources first, then regenerate with the project’s command; stage regenerated output.
- Import conflicts: if unclear, temporarily keep both imports, finish the merge, then let lint/typecheck trim unused imports.
- After resolution: (no conflict markers left).
git diff --check
- 编辑前先检查:
- 使用查看存在冲突的文件;使用
git status/git diff查看冲突片段。git diff --merge - 可选:使用和
git diff :1:path :2:pathvs:1:对比基准版本与我方/对方版本。:3: - 若设置了,冲突标记格式为
merge.conflictstyle=zdiff3我方代码、<<<<<<<基准代码、|||||||、=======对方代码。>>>>>>> - 推断双方代码的意图;优先保证语义正确,再编辑代码。
- 使用
- 优先选择最小化、保留意图的修改,且符合分支的用途。
- 分批解决冲突;必要时,在完成一批逻辑相关的文件冲突解决后,重新运行。
pnpm lint && pnpm test - 仅当某一方的代码应完全保留时,才使用ours/theirs策略。
- 生成文件:先修复源文件,再使用项目命令重新生成文件;将重新生成的输出文件加入暂存区。
- 导入冲突:若无法明确处理,可暂时保留两个导入,完成合并后,通过lint/类型检查工具移除未使用的导入。
- 解决冲突后:执行(确保无残留的冲突标记)。
git diff --check
When to Ask the User
需咨询用户的场景
Ask only when there is no safe default. Prefer a documented decision and proceed otherwise.
Ask when:
- Product behavior cannot be inferred from code, tests, or docs.
- The conflict affects a public API, migration, or contract with no clear safe choice.
- Two designs are equally plausible with no local signal.
- The change risks data loss, schema damage, or irreversible effects without a safe default.
- The branch or remote names cannot be determined locally.
Otherwise complete the merge, note assumptions briefly, and leave reviewable history.
仅在没有安全默认方案时才咨询用户。否则优先按照文档规定的决策执行。
以下场景需咨询用户:
- 无法从代码、测试或文档中推断产品行为时。
- 冲突影响公共API、迁移或契约,且没有明确的安全选择时。
- 两种实现方案同样合理,且本地无参考依据时。
- 修改可能导致数据丢失、 schema损坏或不可逆影响,且无安全默认方案时。
- 无法在本地确定分支或远程仓库名称时。
其他场景下,完成合并操作,简要记录假设,并留下可审查的提交历史。
Present Results to User
向用户展示结果
- State the base branch merged (e.g. ) and the current branch name.
origin/main - List major conflict areas and how they were fixed.
- Report (or what ran) and pass/fail.
pnpm lint && pnpm test - Do not claim a PR was updated or that commits were pushed—those are create-pr-jp and push.
- 说明合并的基准分支(例如)和当前分支名称。
origin/main - 列出主要的冲突区域及解决方式。
- 报告****(或实际运行的检查命令)的执行结果(通过/失败)。
pnpm lint && pnpm test - 切勿声称已更新PR或推送提交——这些操作属于create-pr-jp和push的功能范围。
Notes
注意事项
- Default integration strategy here is merge; do not rebase unless the repository explicitly requires it.
- If fails, diagnose (diverged history) before merging
git pull --ff-only origin <branch>.origin/main
- 本操作默认的集成策略为合并;除非仓库明确要求,否则不要使用变基。
- 若执行失败,需先诊断问题(历史分歧),再合并
git pull --ff-only origin <branch>。origin/main
Troubleshooting
故障排除
| Situation | Action |
|---|---|
| Dirty working tree | Commit or stash before merge |
| Follow Conflict Resolution, then |
| Wrong default branch name | Use |
| Lint/test fails after merge | Fix or revert; do not push broken state—coordinate with push only after green checks |
| 场景 | 操作 |
|---|---|
| 工作区未提交变更 | 合并前提交或暂存变更 |
出现 | 按照冲突解决步骤处理,然后执行 |
| 默认分支名称错误 | 使用 |
| 合并后lint/test失败 | 修复问题或回滚;不要推送存在问题的状态——只有检查通过后,再配合push操作进行推送 |