git-clean-main
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Clean Main
Git Clean Main
Branch strategy that keeps AI development artifacts on while maintaining a clean / free of AI tooling files.
devmainmaster这一分支策略可以将AI开发相关产物保留在分支上,同时让/分支保持整洁,不包含任何AI工具配置文件。
devmainmasterWhen to Use
适用场景
Use this skill when:
- Creating a PR from to
dev/mainmaster - Merging feature branches into /
mainmaster - Setting up a new repo's branch strategy
- The user mentions keeping main clean or separating AI files
Do NOT use this skill when:
- Working entirely within or feature branches
dev - The project explicitly wants AI files in main
在以下场景使用本方案:
- 创建从到
dev/main的PRmaster - 合并功能分支到/
mainmaster - 为新仓库设置分支策略
- 用户提及要保持主分支整洁或分离AI相关文件
以下场景请勿使用本方案:
- 完全在或功能分支内开发
dev - 项目明确要求将AI文件保留在主分支
The Problem
问题背景
AI-assisted development generates tooling files that are valuable for development but don't belong in production branches:
undefinedAI辅助开发会生成大量工具配置文件,这些文件对开发过程很有价值,但不应该出现在生产分支中:
undefinedAI Agent Platforms
AI Agent Platforms
.claude/ ← Claude Code skills, commands, settings
.codex/ ← Codex/OpenAI configuration
.augment/ ← Augment Code
.devin/ ← Devin (Cognition AI)
.bolt/ ← Bolt.new
.v0/ ← Vercel v0
.replit/ ← Replit AI
.claude/ ← Claude Code skills, commands, settings
.codex/ ← Codex/OpenAI configuration
.augment/ ← Augment Code
.devin/ ← Devin (Cognition AI)
.bolt/ ← Bolt.new
.v0/ ← Vercel v0
.replit/ ← Replit AI
AI-Enhanced IDEs
AI-Enhanced IDEs
.cursor/ ← Cursor editor state
.windsurf/ ← Windsurf (Codeium)
.trae/ ← Trae (ByteDance)
.kiro/ ← Kiro (Amazon)
.junie/ ← Junie (JetBrains)
.aide/ ← Aide IDE
.cursor/ ← Cursor editor state
.windsurf/ ← Windsurf (Codeium)
.trae/ ← Trae (ByteDance)
.kiro/ ← Kiro (Amazon)
.junie/ ← Junie (JetBrains)
.aide/ ← Aide IDE
AI Coding Assistants
AI Coding Assistants
.cline/ ← Cline
.roo/ ← Roo Code
.continue/ ← Continue.dev
.cody/ ← Sourcegraph Cody
.aider/ ← Aider
.copilot/ ← GitHub Copilot
.tabnine/ ← Tabnine
.codeium/ ← Codeium
.gemini/ ← Google Gemini
.amazonq/ ← Amazon Q Developer
.cline/ ← Cline
.roo/ ← Roo Code
.continue/ ← Continue.dev
.cody/ ← Sourcegraph Cody
.aider/ ← Aider
.copilot/ ← GitHub Copilot
.tabnine/ ← Tabnine
.codeium/ ← Codeium
.gemini/ ← Google Gemini
.amazonq/ ← Amazon Q Developer
Config & Rules Files
Config & Rules Files
openspec/ ← OpenSpec change proposals and specs
skills-lock.json ← Installed skills lock file
AGENTS.md ← OpenAI Codex agent instructions
.cursorrules ← Cursor rules
.cursorignore ← Cursor editor ignore
.windsurfrules ← Windsurf rules
.clinerules ← Cline rules
.roomodes ← Roo Code modes
.aider.conf.yml ← Aider config
.aiderignore ← Aider ignore
These files should live on `dev` where AI tools use them, but `main`/`master` should stay clean.openspec/ ← OpenSpec change proposals and specs
skills-lock.json ← Installed skills lock file
AGENTS.md ← OpenAI Codex agent instructions
.cursorrules ← Cursor rules
.cursorignore ← Cursor editor ignore
.windsurfrules ← Windsurf rules
.clinerules ← Cline rules
.roomodes ← Roo Code modes
.aider.conf.yml ← Aider config
.aiderignore ← Aider ignore
这些文件应该存放在AI工具使用的`dev`分支上,而`main`/`master`分支需要保持整洁。Strategy
实现策略
main/master ─────●────────●────────●──────── Clean (no AI files)
↑ ↑ ↑
dev ─────●───●───●───●────●───●────●──────── Has AI tooling files
│ │ │
feature/ ─┘ └────────┘ Branch from dev- is the primary working branch — all AI tooling files live here
dev - /
mainreceives clean merges with AI files excludedmaster - Feature branches are created from and merged back to
devdev
main/master ─────●────────●────────●──────── 整洁分支(无AI文件)
↑ ↑ ↑
dev ─────●───●───●───●────●───●────●──────── 包含AI工具配置文件
│ │ │
feature/ ─┘ └────────┘ 从dev分支创建- 是主要的工作分支,所有AI工具配置文件都存放在这里
dev - /
main分支仅接收排除了AI文件的干净合并结果master - 功能分支从创建,开发完成后合并回
devdev
Setup: .gitignore
on main
/master
.gitignoremainmaster配置步骤:在main
/master
分支配置.gitignore
mainmaster.gitignoreOn the / branch, add these entries to :
mainmaster.gitignoregitignore
undefined在/分支的文件中添加以下条目:
mainmaster.gitignoregitignore
undefinedAI tooling (kept on dev, excluded from main)
AI tooling (kept on dev, excluded from main)
AI Agent Platforms
AI Agent Platforms
.claude/
.codex/
.augment/
.devin/
.bolt/
.v0/
.replit/
.claude/
.codex/
.augment/
.devin/
.bolt/
.v0/
.replit/
AI-Enhanced IDEs
AI-Enhanced IDEs
.cursor/
.windsurf/
.trae/
.kiro/
.junie/
.aide/
.cursor/
.windsurf/
.trae/
.kiro/
.junie/
.aide/
AI Coding Assistants
AI Coding Assistants
.cline/
.roo/
.continue/
.cody/
.aider/
.copilot/
.tabnine/
.codeium/
.gemini/
.amazonq/
.cline/
.roo/
.continue/
.cody/
.aider/
.copilot/
.tabnine/
.codeium/
.gemini/
.amazonq/
Config & Rules Files
Config & Rules Files
openspec/
skills-lock.json
AGENTS.md
.cursorrules
.cursorignore
.windsurfrules
.clinerules
.roomodes
.aider.conf.yml
.aiderignore
This ensures that even if AI files somehow get staged, they won't be committed on `main`.openspec/
skills-lock.json
AGENTS.md
.cursorrules
.cursorignore
.windsurfrules
.clinerules
.roomodes
.aider.conf.yml
.aiderignore
这可以确保即使AI文件被意外暂存,也不会被提交到`main`分支。Setup: Merge Script
配置步骤:合并脚本
When merging → , use this workflow to strip AI files:
devmainbash
#!/bin/bash当从合并到时,使用以下工作流剔除AI文件:
devmainbash
#!/bin/bashmerge-to-main.sh — Merge dev into main excluding AI tooling files
merge-to-main.sh — Merge dev into main excluding AI tooling files
set -e
AI_FILES=(
AI Agent Platforms
".claude"
".codex"
".augment"
".devin"
".bolt"
".v0"
".replit"
AI-Enhanced IDEs
".cursor"
".windsurf"
".trae"
".kiro"
".junie"
".aide"
AI Coding Assistants
".cline"
".roo"
".continue"
".cody"
".aider"
".copilot"
".tabnine"
".codeium"
".gemini"
".amazonq"
Config & Rules Files
"openspec"
"skills-lock.json"
"AGENTS.md"
".cursorrules"
".cursorignore"
".windsurfrules"
".clinerules"
".roomodes"
".aider.conf.yml"
".aiderignore"
)
set -e
AI_FILES=(
AI Agent Platforms
".claude"
".codex"
".augment"
".devin"
".bolt"
".v0"
".replit"
AI-Enhanced IDEs
".cursor"
".windsurf"
".trae"
".kiro"
".junie"
".aide"
AI Coding Assistants
".cline"
".roo"
".continue"
".cody"
".aider"
".copilot"
".tabnine"
".codeium"
".gemini"
".amazonq"
Config & Rules Files
"openspec"
"skills-lock.json"
"AGENTS.md"
".cursorrules"
".cursorignore"
".windsurfrules"
".clinerules"
".roomodes"
".aider.conf.yml"
".aiderignore"
)
Switch to main and merge dev
Switch to main and merge dev
git checkout main
git merge dev --no-commit --no-ff
git checkout main
git merge dev --no-commit --no-ff
Remove AI tooling files from the merge
Remove AI tooling files from the merge
for item in "${AI_FILES[@]}"; do
if [ -e "$item" ]; then
git rm -rf --cached "$item" 2>/dev/null || true
rm -rf "$item" 2>/dev/null || true
fi
done
for item in "${AI_FILES[@]}"; do
if [ -e "$item" ]; then
git rm -rf --cached "$item" 2>/dev/null || true
rm -rf "$item" 2>/dev/null || true
fi
done
Commit the clean merge
Commit the clean merge
git commit -m "merge dev into main (AI tooling files excluded)"
git commit -m "merge dev into main (AI tooling files excluded)"
Switch back to dev
Switch back to dev
git checkout dev
undefinedgit checkout dev
undefinedSetup: GitHub Actions (Optional)
配置步骤:GitHub Actions(可选)
For automated clean merges via CI:
yaml
undefined通过CI实现自动整洁合并:
yaml
undefined.github/workflows/clean-merge.yml
.github/workflows/clean-merge.yml
name: Clean Merge to Main
on:
workflow_dispatch:
push:
branches: [dev]
jobs:
clean-merge:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Clean merge to main
run: |
git checkout main
git merge dev --no-commit --no-ff || true
# Remove AI tooling files
AI_ITEMS=".claude .codex .augment .devin .bolt .v0 .replit"
AI_ITEMS="$AI_ITEMS .cursor .windsurf .trae .kiro .junie .aide"
AI_ITEMS="$AI_ITEMS .cline .roo .continue .cody .aider .copilot .tabnine .codeium .gemini .amazonq"
AI_ITEMS="$AI_ITEMS openspec skills-lock.json AGENTS.md .cursorrules .cursorignore .windsurfrules .clinerules .roomodes .aider.conf.yml .aiderignore"
for item in $AI_ITEMS; do
git rm -rf --cached "$item" 2>/dev/null || true
rm -rf "$item" 2>/dev/null || true
done
# Only commit if there are changes
if ! git diff --cached --quiet; then
git commit -m "merge dev into main (AI tooling excluded)"
git push origin main
fi
git checkout devundefinedname: Clean Merge to Main
on:
workflow_dispatch:
push:
branches: [dev]
jobs:
clean-merge:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Clean merge to main
run: |
git checkout main
git merge dev --no-commit --no-ff || true
# Remove AI tooling files
AI_ITEMS=".claude .codex .augment .devin .bolt .v0 .replit"
AI_ITEMS="$AI_ITEMS .cursor .windsurf .trae .kiro .junie .aide"
AI_ITEMS="$AI_ITEMS .cline .roo .continue .cody .aider .copilot .tabnine .codeium .gemini .amazonq"
AI_ITEMS="$AI_ITEMS openspec skills-lock.json AGENTS.md .cursorrules .cursorignore .windsurfrules .clinerules .roomodes .aider.conf.yml .aiderignore"
for item in $AI_ITEMS; do
git rm -rf --cached "$item" 2>/dev/null || true
rm -rf "$item" 2>/dev/null || true
done
# Only commit if there are changes
if ! git diff --cached --quiet; then
git commit -m "merge dev into main (AI tooling excluded)"
git push origin main
fi
git checkout devundefinedPR Workflow
PR工作流程
When creating a PR from to :
devmain- Create PR normally — the PR will show AI files as changed
- Before merging, ensure the target branch excludes AI files
.gitignore - After merge, verify AI files are not present on :
mainbashgit checkout main ls -la .claude .codex .augment .cursor .windsurf .cline .roo .kiro .gemini openspec skills-lock.json 2>&1 # Should show "No such file or directory" for all
Alternatively, create the PR from a temporary clean branch:
bash
undefined当创建从到的PR时:
devmain- 正常创建PR — PR会显示AI文件有变更
- 合并前,确认目标分支的已经排除了AI文件
.gitignore - 合并后,验证分支上不存在AI文件:
mainbashgit checkout main ls -la .claude .codex .augment .cursor .windsurf .cline .roo .kiro .gemini openspec skills-lock.json 2>&1 # 所有文件都应该返回 "No such file or directory"
也可以从临时的整洁分支创建PR:
bash
undefinedCreate a clean branch from dev
从dev创建一个整洁分支
git checkout -b clean/release-to-main dev
git checkout -b clean/release-to-main dev
Remove AI files
移除AI文件
git rm -rf
.claude .codex .augment .devin .bolt .v0 .replit
.cursor .windsurf .trae .kiro .junie .aide
.cline .roo .continue .cody .aider .copilot .tabnine .codeium .gemini .amazonq
openspec skills-lock.json AGENTS.md .cursorrules .cursorignore .windsurfrules .clinerules .roomodes .aider.conf.yml .aiderignore
2>/dev/null git commit -m "chore: remove AI tooling files for main merge"
.claude .codex .augment .devin .bolt .v0 .replit
.cursor .windsurf .trae .kiro .junie .aide
.cline .roo .continue .cody .aider .copilot .tabnine .codeium .gemini .amazonq
openspec skills-lock.json AGENTS.md .cursorrules .cursorignore .windsurfrules .clinerules .roomodes .aider.conf.yml .aiderignore
2>/dev/null git commit -m "chore: remove AI tooling files for main merge"
git rm -rf
.claude .codex .augment .devin .bolt .v0 .replit
.cursor .windsurf .trae .kiro .junie .aide
.cline .roo .continue .cody .aider .copilot .tabnine .codeium .gemini .amazonq
openspec skills-lock.json AGENTS.md .cursorrules .cursorignore .windsurfrules .clinerules .roomodes .aider.conf.yml .aiderignore
2>/dev/null git commit -m "chore: remove AI tooling files for main merge"
.claude .codex .augment .devin .bolt .v0 .replit
.cursor .windsurf .trae .kiro .junie .aide
.cline .roo .continue .cody .aider .copilot .tabnine .codeium .gemini .amazonq
openspec skills-lock.json AGENTS.md .cursorrules .cursorignore .windsurfrules .clinerules .roomodes .aider.conf.yml .aiderignore
2>/dev/null git commit -m "chore: remove AI tooling files for main merge"
Push and create PR to main
推送并创建到main的PR
git push origin clean/release-to-main
gh pr create --base main --title "chore: merge dev to main" --body "Clean merge excluding AI tooling files"
undefinedgit push origin clean/release-to-main
gh pr create --base main --title "chore: merge dev to main" --body "Clean merge excluding AI tooling files"
undefinedFiles to Exclude
需排除的文件清单
| File/Directory | Purpose | Keep on dev | Exclude from main |
|---|---|---|---|
| AI Agent Platforms | |||
| Claude Code skills, commands, settings | Yes | Yes |
| Codex / OpenAI configuration | Yes | Yes |
| Augment Code | Yes | Yes |
| Devin (Cognition AI) | Yes | Yes |
| Bolt.new | Yes | Yes |
| Vercel v0 | Yes | Yes |
| Replit AI | Yes | Yes |
| AI-Enhanced IDEs | |||
| Cursor editor state | Yes | Yes |
| Windsurf (Codeium) | Yes | Yes |
| Trae (ByteDance) | Yes | Yes |
| Kiro (Amazon) | Yes | Yes |
| Junie (JetBrains) | Yes | Yes |
| Aide IDE | Yes | Yes |
| AI Coding Assistants | |||
| Cline | Yes | Yes |
| Roo Code | Yes | Yes |
| Continue.dev | Yes | Yes |
| Sourcegraph Cody | Yes | Yes |
| Aider | Yes | Yes |
| GitHub Copilot | Yes | Yes |
| Tabnine | Yes | Yes |
| Codeium | Yes | Yes |
| Google Gemini | Yes | Yes |
| Amazon Q Developer | Yes | Yes |
| Config & Rules Files | |||
| Change proposals, specs, designs | Yes | Yes |
| Installed skills versions | Yes | Yes |
| OpenAI Codex agent instructions | Yes | Yes |
| Cursor rules | Yes | Yes |
| Cursor editor ignore | Yes | Yes |
| Windsurf rules | Yes | Yes |
| Cline rules | Yes | Yes |
| Roo Code modes | Yes | Yes |
| Aider config | Yes | Yes |
| Aider ignore | Yes | Yes |
| Keep on Both | |||
| Claude Code project instructions | Keep | Keep |
Note:is typically kept on both branches as it serves as project documentation too. Exclude it only if you prefer.CLAUDE.md
| 文件/目录 | 用途 | 保留在dev | 从main排除 |
|---|---|---|---|
| AI Agent平台 | |||
| Claude Code技能、命令、配置 | 是 | 是 |
| Codex / OpenAI配置 | 是 | 是 |
| Augment Code | 是 | 是 |
| Devin (Cognition AI) | 是 | 是 |
| Bolt.new | 是 | 是 |
| Vercel v0 | 是 | 是 |
| Replit AI | 是 | 是 |
| AI增强IDE | |||
| Cursor编辑器状态 | 是 | 是 |
| Windsurf (Codeium) | 是 | 是 |
| Trae (字节跳动) | 是 | 是 |
| Kiro (亚马逊) | 是 | 是 |
| Junie (JetBrains) | 是 | 是 |
| Aide IDE | 是 | 是 |
| AI编码助手 | |||
| Cline | 是 | 是 |
| Roo Code | 是 | 是 |
| Continue.dev | 是 | 是 |
| Sourcegraph Cody | 是 | 是 |
| Aider | 是 | 是 |
| GitHub Copilot | 是 | 是 |
| Tabnine | 是 | 是 |
| Codeium | 是 | 是 |
| Google Gemini | 是 | 是 |
| Amazon Q Developer | 是 | 是 |
| 配置与规则文件 | |||
| 变更提案、规范、设计 | 是 | 是 |
| 已安装技能版本锁定 | 是 | 是 |
| OpenAI Codex agent说明 | 是 | 是 |
| Cursor规则 | 是 | 是 |
| Cursor编辑器忽略规则 | 是 | 是 |
| Windsurf规则 | 是 | 是 |
| Cline规则 | 是 | 是 |
| Roo Code模式 | 是 | 是 |
| Aider配置 | 是 | 是 |
| Aider忽略规则 | 是 | 是 |
| 双分支保留 | |||
| Claude Code项目说明 | 保留 | 保留 |
注意:通常会在两个分支都保留,因为它同时也属于项目文档。如果你不需要也可以排除它。CLAUDE.md
Recommended Scope
适用范围
- Scope: Global (applies to any AI-assisted project)
- Install:
npx skills add skingford/skills --skill git-clean-main -g -y
- 范围:全局(适用于所有AI辅助开发项目)
- 安装命令:
npx skills add skingford/skills --skill git-clean-main -g -y