git-workflow

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Workflow Automation

Git工作流自动化

Automated helpers for common git workflows and branch management tasks.
用于常见Git工作流和分支管理任务的自动化辅助工具。

No Setup Required

无需设置

This skill uses native git commands and bash scripts - no additional tools or SDKs needed. Works immediately in any environment with git installed.
本Skill使用原生Git命令和bash脚本——无需额外工具或SDK。在任何安装了Git的环境中均可立即使用。

Quick Start

快速开始

Create Feature Branch

创建功能分支

Create a new feature branch following naming conventions:
bash
undefined
按照命名规范创建新的功能分支:
bash
undefined

Interactive: prompts for feature name

交互式:提示输入功能名称

cd /path/to/repo bash ~/.claude/skills/git-workflow/scripts/create-feature-branch.sh
cd /path/to/repo bash ~/.claude/skills/git-workflow/scripts/create-feature-branch.sh

Non-interactive: specify feature name

非交互式:指定功能名称

bash ~/.claude/skills/git-workflow/scripts/create-feature-branch.sh "add-user-auth"
bash ~/.claude/skills/git-workflow/scripts/create-feature-branch.sh "add-user-auth"

Creates: feature/add-user-auth

创建:feature/add-user-auth

undefined
undefined

Clean Up Merged Branches

清理已合并分支

Remove local branches that have been merged to main/master:
bash
cd /path/to/repo
删除已合并到main/master的本地分支:
bash
cd /path/to/repo

Preview what would be deleted (dry run)

预览将被删除的内容(试运行)

bash ~/.claude/skills/git-workflow/scripts/cleanup-merged-branches.sh --dry-run
bash ~/.claude/skills/git-workflow/scripts/cleanup-merged-branches.sh --dry-run

Actually delete merged branches

实际删除已合并分支

bash ~/.claude/skills/git-workflow/scripts/cleanup-merged-branches.sh
bash ~/.claude/skills/git-workflow/scripts/cleanup-merged-branches.sh

Force cleanup (skip confirmations)

强制清理(跳过确认)

bash ~/.claude/skills/git-workflow/scripts/cleanup-merged-branches.sh --force
undefined
bash ~/.claude/skills/git-workflow/scripts/cleanup-merged-branches.sh --force
undefined

Interactive Rebase Helper

交互式变基辅助工具

Simplified interactive rebase with common options:
bash
cd /path/to/repo
简化的交互式变基,包含常见选项:
bash
cd /path/to/repo

Rebase last 3 commits

变基最近3次提交

bash ~/.claude/skills/git-workflow/scripts/interactive-rebase.sh 3
bash ~/.claude/skills/git-workflow/scripts/interactive-rebase.sh 3

Rebase since a specific commit

从特定提交开始变基

bash ~/.claude/skills/git-workflow/scripts/interactive-rebase.sh abc123
bash ~/.claude/skills/git-workflow/scripts/interactive-rebase.sh abc123

Rebase onto main

变基到main分支

bash ~/.claude/skills/git-workflow/scripts/interactive-rebase.sh main
undefined
bash ~/.claude/skills/git-workflow/scripts/interactive-rebase.sh main
undefined

Available Scripts

可用脚本

All scripts are located in the skill's
scripts/
directory and can be run with bash.
ScriptPurposeUsage
create-feature-branch.sh
Create feature branches with naming conventions
bash script.sh [feature-name]
cleanup-merged-branches.sh
Clean up merged branches
bash script.sh [--dry-run|--force]
interactive-rebase.sh
Interactive rebase helper
bash script.sh <commit-count|ref>
所有脚本位于Skill的
scripts/
目录中,可通过bash运行。
脚本用途使用方法
create-feature-branch.sh
按照命名规范创建功能分支
bash script.sh [feature-name]
cleanup-merged-branches.sh
清理已合并分支
bash script.sh [--dry-run|--force]
interactive-rebase.sh
交互式变基辅助工具
bash script.sh <commit-count|ref>

Workflow Examples

工作流示例

Starting a New Feature

启动新功能

bash
undefined
bash
undefined

1. Ensure main is up to date

1. 确保main分支是最新的

git checkout main git pull origin main
git checkout main git pull origin main

2. Create feature branch

2. 创建功能分支

bash ~/.claude/skills/git-workflow/scripts/create-feature-branch.sh "user-authentication"
bash ~/.claude/skills/git-workflow/scripts/create-feature-branch.sh "user-authentication"

3. Work on feature...

3. 开发功能...

(make commits)

(提交代码)

4. Push when ready

4. 准备就绪后推送

git push -u origin feature/user-authentication
undefined
git push -u origin feature/user-authentication
undefined

Cleaning Up After PR Merge

PR合并后清理

bash
undefined
bash
undefined

1. Update main branch

1. 更新main分支

git checkout main git pull origin main
git checkout main git pull origin main

2. Preview what will be deleted

2. 预览将被删除的内容

bash ~/.claude/skills/git-workflow/scripts/cleanup-merged-branches.sh --dry-run
bash ~/.claude/skills/git-workflow/scripts/cleanup-merged-branches.sh --dry-run

3. Clean up merged branches

3. 清理已合并分支

bash ~/.claude/skills/git-workflow/scripts/cleanup-merged-branches.sh
undefined
bash ~/.claude/skills/git-workflow/scripts/cleanup-merged-branches.sh
undefined

Squashing Commits Before PR

PR前压缩提交

bash
undefined
bash
undefined

Squash last 5 commits into one

将最近5次提交压缩为1次

bash ~/.claude/skills/git-workflow/scripts/interactive-rebase.sh 5
bash ~/.claude/skills/git-workflow/scripts/interactive-rebase.sh 5

In the editor that opens:

在打开的编辑器中:

- Change 'pick' to 'squash' (or 's') for commits 2-5

- 将第2-5次提交的'pick'改为'squash'(或's')

- Keep first commit as 'pick'

- 保留第一次提交为'pick'

- Save and close

- 保存并关闭

Then edit the combined commit message

然后编辑合并后的提交信息

undefined
undefined

Safety Features

安全特性

All scripts include:
  • Dry run mode - Preview changes before applying
  • Confirmation prompts - Ask before destructive operations
  • Current branch protection - Won't delete the branch you're on
  • Main/master protection - Won't delete main branches
  • Uncommitted changes check - Warns if working directory is dirty
所有脚本包含:
  • 试运行模式 - 应用更改前预览效果
  • 确认提示 - 执行破坏性操作前询问确认
  • 当前分支保护 - 不会删除你当前所在的分支
  • Main/master分支保护 - 不会删除主分支
  • 未提交更改检查 - 若工作目录有未提交更改则发出警告

Prerequisites

前置条件

  • git - Installed and configured (available in most dev environments)
  • bash - Standard shell (available on Linux, macOS, and Git Bash on Windows)
No additional tools, SDKs, or environment variables required.
  • git - 已安装并配置(大多数开发环境中已预装)
  • bash - 标准shell(在Linux、macOS和Windows的Git Bash中可用)
无需额外工具、SDK或环境变量。