用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/microwind/ai-skills --skill git命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | Git工作流管理 |
| description | 当管理Git工作流时,分析分支策略,优化协作流程,解决合并冲突。验证工作流架构,设计CI/CD集成,和最佳实践。 |
| license | MIT |
Git工作流是团队协作开发的核心机制,合理的分支策略和工作流程能够提高开发效率、降低冲突风险、保证代码质量。不当的工作流设计会导致合并困难、版本混乱、协作效率低下。
核心原则: 好的Git工作流应该清晰易懂、适合团队规模、支持持续集成、便于代码审查。坏的工作流会导致分支混乱、冲突频发、部署困难。
始终:
触发短语:
❌ 分支策略混乱
❌ 合并冲突频发
❌ 版本管理混乱
❌ 团队协作低效
#!/bin/bash
# Git Flow 初始化脚本
setup_git_flow() {
echo "初始化Git Flow工作流..."
# 安装git-flow工具
if command -v brew &> /dev/null; then
brew install git-flow-avh
elif command -v apt &> /dev/null; then
sudo apt-get install git-flow
else
echo "请手动安装git-flow工具"
return 1
fi
# 初始化git flow
git flow init -d
# 设置分支前缀
git config gitflow.branch.feature "feature/"
git config gitflow.branch.release "release/"
git config gitflow.branch.hotfix "hotfix/"
git config gitflow.branch.support "support/"
git config gitflow.prefix.versiontag "v"
echo "Git Flow初始化完成!"
}
# 创建功能分支
create_feature_branch() {
local feature_name=$1
echo "创建功能分支: $feature_name"
# 确保在develop分支
git checkout develop
git pull origin develop
# 创建功能分支
git flow feature start $feature_name
# 推送到远程
git flow feature publish $feature_name
echo "功能分支 $feature_name 创建完成"
}
# 完成功能开发
() {
feature_name=
git checkout feature/
git pull origin feature/
run_tests
git flow feature finish
git push origin develop
}
() {
version=
git checkout develop
git pull origin develop
git flow release start
git flow release publish
}
() {
version=
update_version_number
git flow release finish
git push origin main
git push origin develop
git push origin v
}
() {
hotfix_name=
git checkout main
git pull origin main
git flow hotfix start
git flow hotfix publish
}
() {
npm || pytest || mvn
}
() {
version=
[ -f ];
npm version --no-git-tag-version
}
#!/bin/bash
# GitHub Flow 工作流脚本
# 创建功能分支
create_gh_feature() {
local feature_name=$1
local base_branch=${2:-main}
echo "在GitHub Flow中创建功能分支: $feature_name"
# 确保本地代码最新
git checkout $base_branch
git pull origin $base_branch
# 创建并切换到功能分支
git checkout -b feature/$feature_name
# 推送到远程
git push -u origin feature/$feature_name
echo "功能分支创建完成,可以开始开发了"
}
# 提交代码规范检查
commit_with_validation() {
local message=$1
echo "验证提交..."
# 运行代码格式检查
run_linter
# 运行测试
run_tests
# 检查提交信息格式
validate_commit_message "$message"
# 添加所有更改
git add .
# 提交
git commit -m "$message"
echo "提交完成"
}
# 验证提交信息格式
validate_commit_message() {
local message=$1
# 检查提交信息格式
if [[ ! "$message" =~ ^(feat|fix|docs|style|refactor||chore)(\(.+\))?: .{1,50} ]];
1
}
() {
feature_branch=
base_branch=
title=
body=
-v gh &> /dev/null;
gh create \
--base \
-- \
--title \
--body \
--assignee @me
}
() {
pr_number=
-v gh &> /dev/null;
gh view --json statusCheckRollup --jq
}
() {
feature_branch=
git checkout main
git pull origin main
git merge --no-ff feature/
git push origin main
git branch -d feature/
git push origin --delete feature/
}
() {
[ -f ];
npm run lint ||
[ -f ] || [ -f ];
flake8 . ||
black --check . ||
}
#!/usr/bin/env python3
import subprocess
import sys
import json
import re
from datetime import datetime
from typing import List, Dict, Optional
class GitWorkflowManager:
def __init__(self, config_file: str = "git-workflow.json"):
self.config = self.load_config(config_file)
self.branch_types = self.config.get("branch_types", {
"feature": "feature/",
"bugfix": "bugfix/",
"hotfix": "hotfix/",
"release": "release/",
"docs": "docs/"
})
def load_config(self, config_file: str) -> Dict:
"""加载配置文件"""
try:
with open(config_file, 'r') as f:
return json.load(f)
except FileNotFoundError:
return self.create_default_config(config_file)
() -> :
default_config = {
: {
: ,
: ,
: ,
: ,
:
},
: [, , ],
: ,
: ,
: ,
:
}
(config_file, ) f:
json.dump(default_config, f, indent=)
default_config
() -> :
:
result = subprocess.run(
[] + command,
capture_output=,
text=,
check=
)
result.stdout.strip()
subprocess.CalledProcessError e:
()
sys.exit()
() -> :
.run_git_command([, , ])
() -> :
branch_type .branch_types:
ValueError()
prefix = .branch_types[branch_type]
branch_name =
base_branch:
.run_git_command([, base_branch])
.run_git_command([, , base_branch])
:
base_branch = .get_current_branch()
.run_git_command([, , branch_name])
.run_git_command([, , , branch_name])
()
branch_name
() -> :
pattern =
(re.(pattern, message))
() -> :
.validate_commit_message(message):
()
()
files:
file files:
.run_git_command([, file])
:
.run_git_command([, ])
.run_git_command([, , message])
()
() -> :
:
result = subprocess.run([
, , ,
, title,
, body,
, base,
, head
], capture_output=, text=, check=)
()
subprocess.CalledProcessError:
()
() -> :
:
ahead = .run_git_command([, , ])
behind = .run_git_command([, , ])
{
: branch,
: (ahead),
: (behind),
: (ahead) > (behind) >
}
:
{: branch, : }
() -> :
:
.run_git_command([, branch])
.run_git_command([, , branch])
()
:
()
() -> []:
cutoff_date = datetime.now().timestamp() - (days_old * * )
branches = .run_git_command([, ]).split()
old_branches = []
branch branches:
branch = branch.strip().replace(, )
branch .config.get(, []):
:
last_commit = .run_git_command([, , , ])
(last_commit) < cutoff_date:
old_branches.append(branch)
:
old_branches
():
(sys.argv) < :
()
()
sys.exit()
manager = GitWorkflowManager()
command = sys.argv[]
command == :
(sys.argv) < :
()
sys.exit()
branch_type = sys.argv[]
name = sys.argv[]
base = sys.argv[] (sys.argv) >
manager.create_branch(branch_type, name, base)
command == :
(sys.argv) < :
()
sys.exit()
message = sys.argv[]
manager.commit_changes(message)
command == :
current = manager.get_current_branch()
status = manager.get_branch_status(current)
()
()
command == :
current = manager.get_current_branch()
manager.sync_branch(current)
:
()
__name__ == :
main()
#!/bin/bash
# pre-commit hook - 提交前检查
echo "运行提交前检查..."
# 检查代码格式
check_code_format() {
echo "检查代码格式..."
# Python代码检查
if command -v black &> /dev/null; then
black --check .
if [ $? -ne 0 ]; then
echo "错误: Python代码格式不符合规范"
echo "请运行: black ."
exit 1
fi
fi
# JavaScript代码检查
if [ -f "package.json" ]; then
npm run lint
if [ $? -ne 0 ]; then
echo "错误: JavaScript代码检查失败"
exit 1
fi
fi
}
# 运行测试
run_tests() {
echo "运行测试..."
if [ -f "package.json" ]; then
npm test
elif [ -f "requirements.txt" ]; then
python -m pytest
elif [ -f "pom.xml" ]; then
mvn test
fi
if [ $? -ne 0 ];
1
}
() {
message=$( )
[[ ! =~ ^(feat|fix|docs|style|refactor||chore)(\(.+\))?: .{1,50} ]];
1
}
check_code_format
run_tests
[ -f ];
check_commit_message