Token导航 LogoToken导航TokenDH.com
待分类敏感数据github未标认证来源可访问许可证需确认审计提醒

git-branch-pr-workflowgit 分支 pr 工作流程

Agent Skill

git-branch-pr-workflow 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,665

周安装

68

GitHub Stars

28

下载量

539
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:git-branch-pr-workflow(git 分支 pr 工作流程)
来源仓库:https://github.com/laurigates/claude-plugins
仓库路径:skills/git-branch-pr-workflow
安装命令:
npx skills add https://github.com/laurigates/claude-plugins --skill git-branch-pr-workflow
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/laurigates/claude-plugins --skill git-branch-pr-workflow

简介

git-branch-pr-workflow 协助管理从分支创建到 Pull Request 提交的完整流程。

  • 适用于需要自动化或半自动化代码审查与合并流程的团队环境。
  • 可检查前置条件、生成 PR 描述并跟踪状态变更。
  • 涉及写操作时需验证 token 权限及目标仓库访问控制策略。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Git Branch PR Workflow

When to Use This Skill

Use this skill when...Use the alternative when...
Designing the overall branch + PR workflow (main-branch dev, MCP integration)Use git-branch-naming to pick or audit a single branch name
Choosing between git switch, git restore, and feature-branch push patternsUse git-rebase-patterns for linear-history cleanup and stacked PRs
Creating PRs through GitHub MCP tools rather than gh pr createUse git-pr to create PRs from a pushed branch via the gh CLI
Coordinating commit -> push -> PR end-to-endUse git-commit-push-pr for the consolidated commit+push+PR macro

Expert guidance for branch management, pull request workflows, and GitHub integration using modern Git commands and linear history practices.

Core Expertise

  • Main-Branch Development: Work on main locally, push to remote feature branches for PRs
  • Modern Git Commands: Use git switch and git restore instead of checkout
  • Branch Naming: See git-branch-naming skill
  • Linear History: Rebase-first workflow, squash merging - see git-rebase-patterns for advanced patterns
  • GitHub MCP Integration: Use mcp__github__* tools instead of gh CLI

Main-Branch Development (Preferred)

Develop directly on main, push to remote feature branches for PRs. This eliminates local branch management overhead.

Basic Workflow

# All work happens on main
git switch main
git pull origin main

# Make changes, commit on main
git add file.ts
git commit -m "feat(auth): add OAuth2 support"

# Push to remote feature branch (creates PR target)
git push origin main:feat/auth-oauth2

# Create PR using GitHub MCP (head: feat/auth-oauth2, base: main)

Multi-PR Workflow (Sequential Commits)

When you have commits for multiple PRs on main, push specific commit ranges to different remote branches:

# Commits on main:
# abc1234 feat(auth): add OAuth2 support       <- PR #1
# def5678 feat(auth): add token refresh        <- PR #1
# ghi9012 fix(api): handle timeout edge case   <- PR #2

# Push first 2 commits to auth feature branch
git push origin abc1234^..def5678:feat/auth-oauth2

# Push remaining commit to fix branch
git push origin ghi9012^..ghi9012:fix/api-timeout

# Alternative: push from a specific commit to HEAD
git push origin def5678..HEAD:fix/api-timeout

Commit range patterns:

  • git push origin <start>^..<end>:<remote-branch> - Push commit range (inclusive)
  • git push origin <commit>..<commit>:<remote-branch> - Push range (exclusive start)
  • git push origin <commit>..HEAD:<remote-branch> - Push from commit to current HEAD
  • git push origin main:<remote-branch> - Push entire main to remote branch

Benefits

  • No local branch juggling - Always on main
  • Always on latest main - No branch drift
  • Clean local state - No stale branches to clean up
  • Remote branches are ephemeral - Deleted after PR merge
  • Simpler mental model - One local branch, many remote targets

Modern Git Commands (2025)

Switch vs Checkout

Modern Git uses specialized commands instead of multi-purpose git checkout:

# Branch switching - NEW WAY (Git 2.23+)
git switch feature-branch          # vs git checkout feature-branch
git switch -c new-feature          # vs git checkout -b new-feature
git switch -                       # vs git checkout -

# Creating branches with tracking
git switch -c feature --track origin/feature
git switch -C force-recreate-branch

Restore vs Reset/Checkout

File restoration is now handled by git restore:

# Unstaging files - NEW WAY
git restore --staged file.txt      # vs git reset HEAD file.txt
git restore --staged .             # vs git reset HEAD .

# Discarding changes - NEW WAY
git restore file.txt               # vs git checkout -- file.txt
git restore .                      # vs git checkout -- .

# Restore from specific commit
git restore --source=HEAD~2 file.txt    # vs git checkout HEAD~2 -- file.txt
git restore --source=main --staged .    # vs git reset main .

Command Migration Guide

Legacy CommandModern AlternativePurpose
git checkout branchgit switch branchSwitch branches
git checkout -b newgit switch -c newCreate & switch
git checkout -- filegit restore fileDiscard changes
git reset HEAD filegit restore --staged fileUnstage file
git checkout HEAD~1 -- filegit restore --source=HEAD~1 fileRestore from commit

Branch Naming

For comprehensive branch naming conventions including type prefixes, issue linking, and validation patterns, see git-branch-naming.

Quick reference: {type}/{issue}-{description} (e.g., feat/123-user-auth)

Linear History Workflow

Trunk-Based Development

Preferred: Main-branch development (see above) - no local feature branches needed.

Alternative: Local feature branches for complex multi-day work:

# Feature branch lifecycle (max 2 days)
git switch main
git pull origin main
git switch -c feat/user-auth

# Daily rebase to stay current
git switch main && git pull
git switch feat/user-auth
git rebase main

# Interactive cleanup before PR
git rebase -i main
# Squash, fixup, reword commits for clean history

# Push and create PR
git push -u origin feat/user-auth

Use local branches only when:

  • Multi-day complex features requiring isolation
  • Experimental work that might be abandoned
  • Need to switch contexts frequently between unrelated work

Squash Merge Strategy

Maintain linear main branch history:

# Manual squash merge
git switch main
git merge --squash feat/user-auth
git commit -m "feat: add user authentication system

- Implement JWT token validation
- Add login/logout endpoints
- Create user session management

Closes #123"

Interactive Rebase Workflow

Clean up commits before sharing:

# Rebase last 3 commits
git rebase -i HEAD~3

# Common rebase commands:
# pick   = use commit as-is
# squash = combine with previous commit
# fixup  = squash without editing message
# reword = change commit message
# drop   = remove commit entirely

# Example rebase todo list:
pick a1b2c3d feat: add login form
fixup d4e5f6g fix typo in login form
squash g7h8i9j add form validation
reword j1k2l3m implement JWT tokens

Advanced Rebase Patterns

For advanced rebase techniques including --reapply-cherry-picks, --update-refs, --onto, stacked PR workflows, and combining flags, see git-rebase-patterns.

GitHub MCP Integration

Use GitHub MCP tools for all GitHub operations:

# Get repository information
mcp__github__get_me()  # Get authenticated user info

# List and create PRs
mcp__github__list_pull_requests(owner="owner", repo="repo")
mcp__github__create_pull_request(
  owner="owner",
  repo="repo",
  title="feat: add authentication",
  head="feat/auth",
  base="main",
  body="## Summary\n- JWT authentication\n- OAuth support\n\nCloses #123"
)

# Update PRs
mcp__github__update_pull_request(
  owner="owner",
  repo="repo",
  pullNumber=42,
  title="Updated title",
  state="open"
)

# List and create issues
mcp__github__list_issues(owner="owner", repo="repo")

Best Practices

Daily Integration Workflow

# Start of day: sync with main
git switch main
git pull origin main
git switch feat/current-work
git rebase main

# End of day: push progress
git add . && git commit -m "wip: daily progress checkpoint"
git push origin feat/current-work

# Before PR: clean up history
git rebase -i main
git push --force-with-lease origin feat/current-work

Conflict Resolution with Rebase

# When rebase conflicts occur
git rebase main
# Fix conflicts in editor
git add resolved-file.txt
git rebase --continue

# If rebase gets messy, abort and merge instead
git rebase --abort
git merge main

Safe Force Pushing

# Always use --force-with-lease to prevent overwriting others' work
git push --force-with-lease origin feat/branch-name

# Never force push to main/shared branches
# Use this alias for safety:
git config alias.pushf 'push --force-with-lease'

Main Branch Protection

Configure branch rules for linear history via GitHub MCP:

# Require linear history (disable merge commits)
# Configure via GitHub settings or MCP tools
# - Require pull request reviews
# - Require status checks to pass
# - Enforce linear history (squash merge only)

Branch Comparison: Always Use origin/main

CRITICAL: When comparing branches for PR creation, always compare against origin/main (or origin/<base-branch>), never local main. Local main may contain commits that haven't been merged to the remote, causing PRs to include unrelated changes.

Why This Matters

# WRONG: compares against local main (may include unpushed commits)
git log main..HEAD --format='%s'
git diff main...HEAD --stat

# CORRECT: compares against remote main (matches what GitHub will show)
git fetch origin main
git log origin/main..HEAD --format='%s'
git diff origin/main...HEAD --stat

Common scenario: You commit changes on local main for one PR, push to a feature branch, then start working on a second PR. If you compare against local main, the second PR's diff looks correct. But if the first PR hasn't merged yet, origin/main is behind — and comparing against it reveals that both PRs' changes would be included.

Rules

  1. Always fetch before comparing: git fetch origin main
  2. Use origin/main in all diff/log commands for PR context
  3. Base PRs on origin/main when creating branches: git switch -c feat/foo origin/main
  4. The pr-context.sh script handles this automatically

PR Context Gathering (Recommended)

Before creating a PR, gather all context in one command:

# Gather PR context (defaults to main as base, compares against origin/main)
bash "${CLAUDE_PLUGIN_ROOT}/skills/git-branch-pr-workflow/scripts/pr-context.sh"

# Specify different base branch (compares against origin/develop)
bash "${CLAUDE_PLUGIN_ROOT}/skills/git-branch-pr-workflow/scripts/pr-context.sh" develop

The script fetches the latest remote state and compares against origin/<base> to ensure accurate PR context. Outputs: branch info, remote status, commit range and types, diff stats, issue references found in commits, existing PR detection, and CI check results. Use this output to compose the PR title and body. See scripts/pr-context.sh for details.

Pull Request Workflow

PR Title Format

Use conventional commit format in PR titles:

  • feat: add user authentication
  • fix: resolve login validation bug
  • docs: update API documentation
  • chore: update dependencies

PR Body Template

## Summary
Brief description of changes

## Changes
- Bullet points of key changes
- Link related work

## Testing
How changes were tested

## Issue References
<!-- Use GitHub autolink format - ALWAYS include relevant issues -->
Closes #123
<!-- Or use: Fixes #N, Resolves #N, Refs #N -->

Issue Reference Guidelines:

  • Use Closes #N / Fixes #N / Resolves #N to auto-close issues on merge
  • Use Refs #N / Related to #N for context without auto-closing
  • Cross-repo: Fixes owner/repo#N
  • Multiple: Fixes #1, fixes #2, fixes #3 (repeat keyword)

PR Creation Best Practices

  • One focus per PR - Single logical change
  • Small PRs - Easier to review (< 400 lines preferred)
  • ALWAYS link issues - Use GitHub autolink format for traceability:

- Closing keywords: Closes #123, Fixes #456, Resolves #789 - Reference without closing: Refs #234, Related to #567 - Cross-repository: Fixes owner/repo#123 - Multiple issues: Fixes #1, fixes #2 (repeat keyword for each)

  • Add labels - Use GitHub labels for categorization
  • Request reviewers - Tag specific reviewers when needed

Troubleshooting

Branch Diverged from Remote

# Pull with rebase to maintain linear history
git pull --rebase origin feat/branch-name

Note: git reset --hard is rarely needed. Most "diverged" states resolve cleanly with git pull.

Committed to Main (Expected Workflow)

With main-branch development, committing to main is the expected workflow:

# Commits are already on main - just push to remote feature branch
git push origin main:feat/new-feature

# Create PR using GitHub MCP (head: feat/new-feature, base: main)

# After PR is merged, local main resolves itself:
git pull origin main  # Fast-forward merge handles this cleanly

Why git pull works (no reset needed):

  • Commits exist on both local main and remote feature branch
  • When PR merges to remote main, your local main is behind by the same commits
  • git pull recognizes the commits and fast-forwards cleanly
  • No history rewriting, no data loss, no merge conflicts

After pushing to a PR branch: Wait for the PR to merge, then use git pull to sync automatically.

Rebase Conflicts Are Too Complex

# Abort rebase and use merge instead
git rebase --abort
git merge main

Safe Operations

Recognizing Normal States

These states are expected during development - proceed confidently:

StateMeaningAction
Unstaged changes after pre-commitFormatters modified filesStage with git add -u and continue
Modified files after running formattersExpected auto-fix behaviorStage before committing
Pre-commit exit code 1Files were modifiedStage modifications, re-run pre-commit
Branch behind remoteRemote has newer commitsPull or rebase as appropriate

Confirmation-Required Commands

Request user confirmation before running destructive commands:

# These require explicit user approval:
git branch -d/-D       # "Delete local branch X?"
git push origin --delete  # "Delete remote branch X?"
git reset --hard       # "Discard uncommitted changes?"
git clean -fd          # "Remove untracked files?"

When State is Unclear

When encountering unexpected state:

  1. Run diagnostic commands (git status, git log --oneline -5)
  2. Report findings clearly
  3. Present options and wait for guidance

Recovery Workflows

Pre-commit Modifies Files

This is normal formatter/linter behavior:

# 1. Check what changed
git status

# 2. Stage modified files
git add -u

# 3. Continue with commit
git commit -m "feat(feature): description"

Push Rejected (Non-Fast-Forward)

Remote has newer commits:

# Option 1: Rebase local changes on top (preferred for linear history)
git pull --rebase origin <branch>

# Option 2: Merge remote changes
git pull origin <branch>

# Option 3: Overwrite remote (your branch only, use cautiously)
git push --force-with-lease

Commit Fails

  1. Read the error message
  2. Common causes:

- Pre-commit hooks failed → Fix issues and retry - No staged changes → Stage files first - Empty commit message → Provide message

  1. Fix the underlying issue and retry

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.01%
按下载量换算199

Claude

29.27%
按下载量换算158

Cursor

18.82%
按下载量换算101

Gemini CLI

9.17%
按下载量换算49

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills