git-clean-main

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Clean Main

Git Clean Main

Branch strategy that keeps AI development artifacts on
dev
while maintaining a clean
main
/
master
free of AI tooling files.
这一分支策略可以将AI开发相关产物保留在
dev
分支上,同时让
main
/
master
分支保持整洁,不包含任何AI工具配置文件。

When to Use

适用场景

Use this skill when:
  • Creating a PR from
    dev
    to
    main
    /
    master
  • Merging feature branches into
    main
    /
    master
  • 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
    dev
    or feature branches
  • The project explicitly wants AI files in main
在以下场景使用本方案:
  • 创建从
    dev
    main
    /
    master
    的PR
  • 合并功能分支到
    main
    /
    master
  • 为新仓库设置分支策略
  • 用户提及要保持主分支整洁或分离AI相关文件
以下场景请勿使用本方案:
  • 完全在
    dev
    或功能分支内开发
  • 项目明确要求将AI文件保留在主分支

The Problem

问题背景

AI-assisted development generates tooling files that are valuable for development but don't belong in production branches:
undefined
AI辅助开发会生成大量工具配置文件,这些文件对开发过程很有价值,但不应该出现在生产分支中:
undefined

AI 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
  • dev
    is the primary working branch — all AI tooling files live here
  • main
    /
    master
    receives clean merges with AI files excluded
  • Feature branches are created from
    dev
    and merged back to
    dev
main/master ─────●────────●────────●──────── 整洁分支(无AI文件)
                 ↑        ↑        ↑
dev ─────●───●───●───●────●───●────●──────── 包含AI工具配置文件
         │       │        │
feature/ ─┘       └────────┘                  从dev分支创建
  • dev
    是主要的工作分支,所有AI工具配置文件都存放在这里
  • main
    /
    master
    分支仅接收排除了AI文件的干净合并结果
  • 功能分支从
    dev
    创建,开发完成后合并回
    dev

Setup:
.gitignore
on
main
/
master

配置步骤:在
main
/
master
分支配置
.gitignore

On the
main
/
master
branch, add these entries to
.gitignore
:
gitignore
undefined
main
/
master
分支的
.gitignore
文件中添加以下条目:
gitignore
undefined

AI 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
dev
main
, use this workflow to strip AI files:
bash
#!/bin/bash
当从
dev
合并到
main
时,使用以下工作流剔除AI文件:
bash
#!/bin/bash

merge-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
undefined
git checkout dev
undefined

Setup: 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 dev
undefined
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 dev
undefined

PR Workflow

PR工作流程

When creating a PR from
dev
to
main
:
  1. Create PR normally — the PR will show AI files as changed
  2. Before merging, ensure the target branch
    .gitignore
    excludes AI files
  3. After merge, verify AI files are not present on
    main
    :
    bash
    git 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
当创建从
dev
main
的PR时:
  1. 正常创建PR — PR会显示AI文件有变更
  2. 合并前,确认目标分支的
    .gitignore
    已经排除了AI文件
  3. 合并后,验证
    main
    分支上不存在AI文件:
    bash
    git 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
undefined

Create 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"
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"

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"
undefined
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"
undefined

Files to Exclude

需排除的文件清单

File/DirectoryPurposeKeep on devExclude from main
AI Agent Platforms
.claude/
Claude Code skills, commands, settingsYesYes
.codex/
Codex / OpenAI configurationYesYes
.augment/
Augment CodeYesYes
.devin/
Devin (Cognition AI)YesYes
.bolt/
Bolt.newYesYes
.v0/
Vercel v0YesYes
.replit/
Replit AIYesYes
AI-Enhanced IDEs
.cursor/
Cursor editor stateYesYes
.windsurf/
Windsurf (Codeium)YesYes
.trae/
Trae (ByteDance)YesYes
.kiro/
Kiro (Amazon)YesYes
.junie/
Junie (JetBrains)YesYes
.aide/
Aide IDEYesYes
AI Coding Assistants
.cline/
ClineYesYes
.roo/
Roo CodeYesYes
.continue/
Continue.devYesYes
.cody/
Sourcegraph CodyYesYes
.aider/
AiderYesYes
.copilot/
GitHub CopilotYesYes
.tabnine/
TabnineYesYes
.codeium/
CodeiumYesYes
.gemini/
Google GeminiYesYes
.amazonq/
Amazon Q DeveloperYesYes
Config & Rules Files
openspec/
Change proposals, specs, designsYesYes
skills-lock.json
Installed skills versionsYesYes
AGENTS.md
OpenAI Codex agent instructionsYesYes
.cursorrules
Cursor rulesYesYes
.cursorignore
Cursor editor ignoreYesYes
.windsurfrules
Windsurf rulesYesYes
.clinerules
Cline rulesYesYes
.roomodes
Roo Code modesYesYes
.aider.conf.yml
Aider configYesYes
.aiderignore
Aider ignoreYesYes
Keep on Both
CLAUDE.md
Claude Code project instructionsKeepKeep
Note:
CLAUDE.md
is typically kept on both branches as it serves as project documentation too. Exclude it only if you prefer.
文件/目录用途保留在dev从main排除
AI Agent平台
.claude/
Claude Code技能、命令、配置
.codex/
Codex / OpenAI配置
.augment/
Augment Code
.devin/
Devin (Cognition AI)
.bolt/
Bolt.new
.v0/
Vercel v0
.replit/
Replit AI
AI增强IDE
.cursor/
Cursor编辑器状态
.windsurf/
Windsurf (Codeium)
.trae/
Trae (字节跳动)
.kiro/
Kiro (亚马逊)
.junie/
Junie (JetBrains)
.aide/
Aide IDE
AI编码助手
.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
配置与规则文件
openspec/
变更提案、规范、设计
skills-lock.json
已安装技能版本锁定
AGENTS.md
OpenAI Codex agent说明
.cursorrules
Cursor规则
.cursorignore
Cursor编辑器忽略规则
.windsurfrules
Windsurf规则
.clinerules
Cline规则
.roomodes
Roo Code模式
.aider.conf.yml
Aider配置
.aiderignore
Aider忽略规则
双分支保留
CLAUDE.md
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